WoodHacker Posted October 8, 2015 Share Posted October 8, 2015 Not sure I'm in the right place, but here goes: I'm running Phaser 2.2.4 and have read the Interphase book. My question is this: If you have a hero sprite, how do you pass him from one state to another? Passing him into the Init function in the new state does not seem to work. I pass him to Init, which seems to work, but when I run this.professor.body.velocity.y = 200; I get an error. My code looks like this: init: function (p){ this.professor = p;} ..... update: function () { this.physics.arcade.collide(this.professor, this.layer3); this.professor.body.velocity.y = 200; .... Link to comment Share on other sites More sharing options...
rich Posted October 8, 2015 Share Posted October 8, 2015 Unless you have a specific need to keep the exact same sprite from one state to the next, why not just re-create him in each state? shohan4556 1 Link to comment Share on other sites More sharing options...
WoodHacker Posted October 8, 2015 Author Share Posted October 8, 2015 Well, that's what I've been doing, but it seems to me there should be a way to carry him from state to state. As games get more complex (and mine is fairly complex) the hero will move through many states. My game has him going from room to room in a huge castle. Am I going about this wrong? Each room has its own gameplay. Link to comment Share on other sites More sharing options...
rich Posted October 8, 2015 Share Posted October 8, 2015 A Sprite is a display object. If you change state you're effectively destroying everything on the display and recreating it again in the new state. Your Hero sounds like it should be a higher level up than this, and that the sprite that visually represents the hero is just a small part of it (and therefore doesn't matter if it's re-created from state to state, as the core Hero object can easily exist outside of this). Link to comment Share on other sites More sharing options...
Recommended Posts