Skip to content
← Back to Community
Kaboom JS - How to change sprite
Profile icon
CodedEntity

I am working on a game, and am trying to change the sprite of the player to something else after colliding with a item.
i have tried -
player.spriteID = 'abc2'
and
player.sprite('abc2')
but they dont work. Is there a way to change sprites through collision?

Voters
Profile icon
CodedEntity
Comments
hotnewtop
Profile icon
CodedEntity

ok I did some digging and I have found out that we can change sprite using the use() method:
player.use(sprite('abc2))

Profile icon
RobertR9

@CodedEntity Wonderful! Thanks a lot, I was bumping my head against the wall since days figuring out, how to do that in recent Kaboom version.
Lifesaver!

Profile icon
SixBeeps

I take it that 1.) abc2 is a real sprite that exists, and 2.) player is properly defined in the collision scope. In that case, the first one should be correct. Can you link your Repl so that we can have the full context to what's hapenning?

Profile icon
CodedEntity

@SixBeeps https://replit.com/@CodedEntity/JustTesting i was testing to learn about kaboom.