Using a title screen to determine a sprite in a future scene

Hello,

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.

and

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)

https://labs.phaser.io/edit.html?src=src/scenes/registry%20data%20exchange.js&v=3.52.0

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

As mentioned before, that way Phaser intends to communicate data between scenes is with the data manager.

It can be accessed from any scene with:

this.registry

Taken from the official documentation:

Sets a value for the given key. If the key doesn’t already exist in the Data Manager then it is created.

data.set('name', 'Red Gem Stone');

You can also pass in an object of key value pairs as the first argument:

data.set({ name: 'Red Gem Stone', level: 2, owner: 'Link', gold: 50 });

To get a value back again you can call get:

data.get('gold');

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: