Help with changing sprites during runtime

Hi!
I’m trying to make game where the player character can change colours during the runtime by colliding with a certain checkpoint/marker but I’m struggling to implement this into my player script. I’ve seen people talk about using sprite.play_flipbook(url, id) to change the animation but I’m not sure how I would do this for multiple colours/animations (blue, green and both). Also would this go in the update_animations() or on_message() function?
Thanks!

Sprites do have this tint property that you can use to tint their color. This can be changed through go property changing: go.set("#sprite", "tint", vmath.vector4(1, 0, 0, 1)) for example. You can also just tint only the R, G, B, or A value with changing “tint” to “tint.x/tint.y/tint.z/tint.w”, but make sure the value put in is not a vector and is just a number. Or you could also just add more images in the atlas manually with the different colors and change them through sprite.play_flipbook(url, id).

For when you’d do this, since you said that it would happen upon a collision, this would likely happen in the on_message() function as this is the function that picks up collisions. Check out the Defold collision message manual if you don’t know how this aspect works.

1 Like