Ask coding questions

← Back to all posts
Why isn't this isTouch function working?
h
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
p1ckl3
Comments
hotnewtop
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()

p1ckl3

Like this @SixBeeps?

SixBeeps

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

p1ckl3

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

SixBeeps
STCollier

@p1ckl3 here's a tag example:

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

STCollier

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

p1ckl3

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

STCollier
STCollier

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

p1ckl3

Thanks you @STCollier!