Skip to content
← Back to Community
Why isn't this isTouch function working?
Profile icon
h
has Hacker Plan
p1ckl3

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
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
Profile icon
STCollier

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

Profile icon
p1ckl3

Thanks you @STCollier!