I am creating a space shooter game with a title screen, where the user will click on one of eight different space ships. I want to make it so that once a user clicks on their desired ship, the scene is the changed from the title screen to the gameplay. Nearly everything works now, but I can’t seem to figure out how to manipulate the sprite in the gameplay scene when it’s decided in an entirely different scene. Is this possible?
In the gameplay scene, the player’s ship is initialized like this for now:
this.player = this.physics.add.sprite(550 / 2, config.height - 75, “player”);
This was intended to be temporary, but I’m not sure if “player” can become some sort of variable that’s shared among scenes.
maybe the magic registry, for your one-stop all-needs (if thats still in it … i found that very convenient)
if you store “player” as a string there you can assign it from registry later anywhere in the game
something along
get the key from selecting,then
this.registry.set(‘store1’,selectedshipkey)
you can set a variable to the stored value later anywhere (or maybe, … i think its possible to use registry.values inline as well)
a simple way but i assume you need to clear those things manually if you think space is important for the devices you’re aiming at since they stick around for the whole game
Or you can access the value directly via the values property, where it works like any other variable:
data.values.gold += 50;
More about scenes and data communications:
In your case I would create a spritesheet with all the possible ships (obviously each frame must have the same size). You then simply save the current frame in the data manager and access it to set the current frame of the ship. In case you have animated ships, have a look at my super mario land example: