pandavigoureux29 Posted May 8, 2014 Share Posted May 8, 2014 Hi all. I've been encountering this issue since some time now : I know how to initialise P2 Physics game.physics.startSystem(Phaser.Physics.P2JS);When I do this in the create of a State, everything is okay, I can enable bodies on sprites and set my callback events ( onBeginContact ...). I also listen to the broadphase callback and this is working. The thing is, if I move the code above to another State create() function, or in the Game create() function, I lose all my events, the physics seems weird, and the broadphase callback setting trigger an error ( about pairs parent ) Do I have to start a different physics system for each State? That seems weird to me. Thanks Link to comment Share on other sites More sharing options...
JP91 Posted May 8, 2014 Share Posted May 8, 2014 I do so, this is my main state.var Play = function (){};Play.prototype = {preload:function(){},create:function(){game.physics.startSystem(Phaser.Physics.P2JS);enemigo.create();jugador.create();},update:function(){enemigo.update();jugador.update();};},}; Link to comment Share on other sites More sharing options...
pandavigoureux29 Posted July 16, 2014 Author Share Posted July 16, 2014 Sorry, I wasn't notified of your answer ( although I'm the one who initiated it) What you're doing is initializing the P2 system in your playState. This is also working for me. What's not is when I initialize it in a previours state ( LoadingState for example ). Well, it seems to work but contact events are not triggered anymore. Link to comment Share on other sites More sharing options...
Heppell08 Posted July 16, 2014 Share Posted July 16, 2014 Are you wanting to have a whole new set up of physics in a new state but with previously set out rules in another state?that i don't think you can do but if you kill() your previous state and load a new state and start the whole physics system, sprite creation and more then i don't see why it should error on you asking as the previous physics enabled state is no longer running. Link to comment Share on other sites More sharing options...
pandavigoureux29 Posted July 16, 2014 Author Share Posted July 16, 2014 yeah my plan was to create the Physics system once and for all. Are you saying the common usage is to actually restart a new system for each state ? Link to comment Share on other sites More sharing options...
Heppell08 Posted July 16, 2014 Share Posted July 16, 2014 I would assume if you put the startSystem of the physics in your boot.js and then test it with sprites using the physics in any state afterwards then it should work.i have used states and variables widely around my state set up so try setting the physics up first then set up the sprite physics and spread them out into states for testing. Link to comment Share on other sites More sharing options...
pandavigoureux29 Posted July 16, 2014 Author Share Posted July 16, 2014 That's actually what's not working. Let's say I have : boot.js => play.js If I start my system in boot and create my sprites in play, the physics will work fine but the contact events won't be triggered. ( I'm talking about onBeginContact and onEndContact here) By starting my system in play.js it fixes the issue. Link to comment Share on other sites More sharing options...
Heppell08 Posted July 16, 2014 Share Posted July 16, 2014 yeah so you were thinking along the same lines as me then. Well i really dont know.Only thing i can say is to initate the creation of the sprites in the play.js but have the physics started in boot? If that doesnt work then you will have to kill the state and initiate a new state as well as starting the physics back up. Link to comment Share on other sites More sharing options...
pandavigoureux29 Posted July 16, 2014 Author Share Posted July 16, 2014 Well I guess I will have to stick with my current solution: do a startSystem in each create() method of my states. I don't really know what's behind this method. I hope it won't slow down the loading of my states in the end. Thanks for trying to help Link to comment Share on other sites More sharing options...
Recommended Posts