Jump to content

Reuse a group in multiple states


Jody Thai
 Share

Recommended Posts

Hi all,

 

I have a group and want to reuse it in multiple states because the content inside this group will be the same, but currently it won't work in the second state, the group content is existed in this second state but it just never show up.

 

Here is my codes:

 

I have two variables in my main.js as below:

(function (DaoMai) {    var width = 640,        height = width/(16/9);		DaoMai.sceneBg;	DaoMai.timeLeft = 60;	DaoMai.countDownTimer = null;	DaoMai.gameTime = 60;	DaoMai.totalItem = 10; // all Tet items, including incorrect items	DaoMai.selectedTree = null;	DaoMai.mobileWidth = 0;    DaoMai.mobileHeight = 0;    DaoMai.gameRatio = 16/9;    DaoMai.items = [];    DaoMai.effectWrongItem;    DaoMai.countDownTimer = null;    DaoMai.timerInterval = null;    DaoMai.bloomingTree;    DaoMai.finalTree;    DaoMai.finalTreeGroup;    DaoMai.chosenTree = null; // 0 is cay Dao, 1 is cay Mai    DaoMai.correctItem = 0;    DaoMai.checkIcon; // the check icon at state choose tree    DaoMai.checkIconTween;    DaoMai.game = new Phaser.Game(width, height, Phaser.CANVAS, 'game');    DaoMai.game.state.add('Boot', DaoMai.Boot, true);	DaoMai.game.state.add('Preloader', DaoMai.Preloader);	DaoMai.game.state.add('MainMenu', DaoMai.MainMenu);	DaoMai.game.state.add('StateChooseTree', DaoMai.StateChooseTree);	DaoMai.game.state.add('StateTreeBlooming', DaoMai.StateTreeBlooming);	DaoMai.game.state.add('StateMain', DaoMai.StateMain);		//	Now start the Boot state.	DaoMai.game.state.start('Boot');}(window.DaoMai = window.DaoMai || {}));

Then I create a group and a sprite in my state_tree_blooming.js.

DaoMai.finalTreeGroup = this.game.add.group();DaoMai.finalTree = DaoMai.finalTreeGroup.create(0, 0, 'cayDaoBlooming');

And then I want to re-use this group in another state, in this case state_I just want to re-locate this group in main.js as below:

DaoMai.finalTreeGroup.x = 285;DaoMai.finalTreeGroup.y = 5;

And nothing shows up. So I don't know whether a group can be used in multiple state or not, any help would be greatly appreciate.

 

Thanks,

Jody

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...