liakos1992 Posted March 20, 2016 Share Posted March 20, 2016 I want to combine phaser arcade physics with some custom physics of my own. But it seems that objects with velocity are playing 1 tick ahead of objects whose x and y properties are changed in the update function (like "sprite.x += 10;"). What I need is to render the game AFTER the update loop. Is there any way to do this? I've been searching this for weeks and haven't found anything yet. Link to comment Share on other sites More sharing options...
rich Posted March 20, 2016 Share Posted March 20, 2016 Render always happens after update. However update happens before the physics step, because it's the function in which you're supposed to change object speeds, check collisions, etc, so it can't happen after it. If you need to do something post-update, but before the render, then use the prerender function to do it. Link to comment Share on other sites More sharing options...
liakos1992 Posted March 20, 2016 Author Share Posted March 20, 2016 i see. how to use it is it a method? Link to comment Share on other sites More sharing options...
rich Posted March 20, 2016 Share Posted March 20, 2016 https://github.com/photonstorm/phaser/blob/master/src/core/State.js#L167 liakos1992 1 Link to comment Share on other sites More sharing options...
liakos1992 Posted March 20, 2016 Author Share Posted March 20, 2016 Nice. Used game.state.preRender = function() { // my code here } inside the "create()" function and it's working fine. Link to comment Share on other sites More sharing options...
rich Posted March 20, 2016 Share Posted March 20, 2016 It's a State method, so the state that your create function is in, just add a preRender function as well and it'll be automatically called. Link to comment Share on other sites More sharing options...
Recommended Posts