Jump to content

Phaser 2.2.4 States


WoodHacker
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

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