Atlas image replacement

Hello! I have a game, in it there is a prototype ball.go this prototype has images of a soccer ball. Can I download a collection with a new atlas with a basketball in it via live update and then replace the images in the prototype with the basketball?

Yes, Live Update opens up a lot of such possibilities, especially when combined with the Dynamic Property option on factories and Resource Properties. It is an advanced feature though and a bit more complicated to work with compared to a project where you have everything included in the main project.

Thank you! This is just what I needed! But is there somewhere an example of how to replace atlas and image of an object? I still can’t find an example. I tried a bit with go.property but in that case we need to specify the atlas at once

To use LiveUpdate in your scenario:

  • Create one collection with the ball.go containing a sprite which references an atlas containing the soccer ball
  • Create one collection with the atlas containing a basketball
  • In the same collection you also add a game object and a script with a resource property referencing the atlas:
go.property("my_basketball_atlas", resource.atlas("/basketball_atlas.atlas"))
  • Reference the basketball collection from a collection proxy and check the Exclude checkbox to get it exported into a LiveUpdate archive.
  • Bundle your project to get the main game and your live update archive
  • Load the zip archive containing this collection and mount it using liveupdate.add_mount()
  • Replace the image used in ball.go with the one in the loaded collection:
local basketball_atlas = go.get(url_to_script_with_property, "my_basketball_atlas")

-- spawn a ball and replace the image
local ball = factory.create("#ballfactory")
local ball_sprite = msg.url(nil, ball, "sprite")
go.set(ball_sprite, "image", basketball_atlas)

Alternative to the above is if you have a basketball.go in the excluded collection and use factory.set_prototype() to replace which game object that the ball factory spawns.

2 Likes

Thanks a lot!

Can you please tell me if it is possible to get a certain image from an atlas? For example, besides a basketball, I have a golf ball and I want to load a golf ball or a basketball

You use sprite.play_flipbook() to play/show a specific animation/image from an atlas.

1 Like