Skip to content
Sign upLog in
← Back to Community

Why isn't this isTouch function working?

Profile icon
p1ckl3Hacker

I am working on a weird game like thing and I need to collect what the user clicks. I know how to do kaboom but its been a while so I don't remember how to do the function to for seeing if something is clicked. Anybody know how to see if the sprite is clicked?

Answered by STCollier [earned 5 cycles]
View Answer
Voters
Profile icon
p1ckl3
Comments
hotnewtop
Profile icon
SixBeeps

SpriteComp objects don't have events on them. Instead, you give them a tag and register a global event handler using one of the built-in functions.

Looks like you need clicks()

Profile icon
p1ckl3

Like this

@SixBeeps
?

Profile icon
SixBeeps

@p1ckl3
Like I said, you have to do it using tags, as the SpriteComp object doesn't have any events.

Profile icon
p1ckl3

Sorry

@SixBeeps
. I don't remember kaboom very well. What do you mean by tags?

Profile icon
SixBeeps

@p1ckl3
https://kaboomjs.com/#:~:text=//%20give%20it%20tags%20for%20controlling%20group%20behaviors%0A%20%20%20%20%22player%22%2C%0A%20%20%20%20%22friendly%22%2C

Profile icon
STCollier

@p1ckl3
here's a tag example:

const player = add([ sprite("bean"), area(), solid(), "player" //this is a tag in kaboom ])

Profile icon
STCollier

As you can see in the kaboom docs, you need a tag to specify the object your're clicking.

image

Profile icon
p1ckl3

Sorry

@STCollier
and
@SixBeeps
as you can see I am very bad at this. Do you mind forking this?

Profile icon
STCollier

@p1ckl3
https://replit.com/@STCollier/PixelPet?v=1

Profile icon
STCollier

code: clicks("d1", (d1) => { d1.use(body()) debug.log("clicked") })

Profile icon
p1ckl3

Thanks you

@STCollier
!