How to change gameobject background image (SOLVED)

I have a set of game objects which show two images

  • An animated forground image - which uses an Animation Group defined in an Atlas
  • A static background image

I have four background images defined in another atlas. While I know how to change the animated image at run time by sending a play_animation message it is not clear to me how I would go about changing the background image at run time. Can this be done?

While the end result is the same I would recommend that you use sprite.play_flipbook() instead.

You can use sprite.play_flipbook() to change to any other image in the same atlas. It doesn’t have to be an actual animation.

Thanks. I had in the interim simply created an “animation group” with just one sprite image and a frame rate of 1 fps. Then when I need to change the action “animation” at run time I send play_animation as I would do for a normal animation. This works - not surprising. Why is it better to use play_flipbook?

It’s the same to send a play_animation message and calling sprite.play_flipbook(). The sprite.play_flipbook() function does generate a play_animation message. But you get auto complete for the function.

Thanks