Ask coding questions

← Back to all posts
Kaboom JS - How to change sprite
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
CodedEntity
Comments
hotnewtop
CodedEntity

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

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?

CodedEntity

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