Reputation: 45
IS that possible to get the sprite position data and pass it to next scene?
Scene 1
preload() {
this.load.image('neutral_emoji', '/image/neutral.png');
this.load.image('sad_emoji', '/image/sad.png');
this.load.image('happy_emoji', '/image/smiley.png');
}
create() {
var emoji = ['sad_emoji', 'happy_emoji'];
this.neutral = this.add.image(0, 0, 'neutral_emoji');
this.emotion = this.add.image(0, 0, emoji[Math.floor(Math.random() * emoji.length)]);
this.aGrid = new AlignGrid({scene: this,rows: 11,cols: 11});
this.aGrid.placeAtIndex(57,this.neutral);
this.aGrid.placeAtIndex(63,this.emotion);
Align.scaleToGameW(this.neutral,.1);
Align.scaleToGameW(this.emotion,.1);
}
As the code above the neutral emoji is placed at position 57 and sad/smiley is placed at 63.I would like to pass the position data and texture key to Scene 2
Upvotes: 1
Views: 48
Reputation: 14820
Depending how you are starting the next scene
, but yes, just can pass the data
you want to pass, to the next scene
as parameter
// first Scene 'data' to pass
this.scene.start('NextScene', {key:'texure_key', x: 1, y: 1});
This parameter will be passed to the function calls of methods init
and create
, so you can retrieve the data from that parameter.
// Next Scene
function create( data ){
// ...
}
function init( data ){
// ...
}
Upvotes: 1