mariogarranz Posted August 4, 2014 Share Posted August 4, 2014 I use a classic states set with Boot, Preloader, Menu and Game. Whenever I start the Game state, I have noticed it will start runnin 1 or 2 seconds (even more, depending on the device speed) before the scene is rendered and playable.Is there any way to stop the execution until the state is completely ready? The only solution I've found so far is to simulate a load bar with a fixed time, so that slower devices start with the load bar, say, at 50% and faster ones see most of the load bar progression, but this is just a workaround. Thanks in advance for your help. Link to comment Share on other sites More sharing options...
eguneys Posted August 4, 2014 Share Posted August 4, 2014 State has a few hook methods that gets called at specific times http://www.html5gamedevs.com/topic/1372-phaser-function-order-reserved-names-and-special-uses/. You create your game objects in `create` hook method. After that your state should be playable. So you can create all the game objects in that method, and that call a `startPlaying` method that will start the game play. Link to comment Share on other sites More sharing options...
mariogarranz Posted August 4, 2014 Author Share Posted August 4, 2014 Thanks eguneys, but I already use different functions (preload, create, update) for every state. The problem is that the update loop seems to start before the state is even rendered for the first time, while it's still creating sprites and other game objects. Say, for example, that my game state starts a countdown from 3 to 0, then sometimes you don't see anything until the countdown is already at 2, or on other devices even at 1. Link to comment Share on other sites More sharing options...
rich Posted August 4, 2014 Share Posted August 4, 2014 update and render are not started until create has been called first. However it's entirely possible for you to launch expensive async processes within create. Decoding audio for example is a classic one. But just generally creating masses of images can sometimes be enough to cause a slight delay as they are all uploaded to the GPU - this is very device specific though and easy to mitigate by carefully loading and pre-seeding the GPU. It's also impossible to get any kind of event from the hardware to know when this process has finished, so Phaser couldn't report it back even if it wanted to. update will always fire before render, as that's the order in which they're supposed to happen. Carlos and mariogarranz 2 Link to comment Share on other sites More sharing options...
mariogarranz Posted August 4, 2014 Author Share Posted August 4, 2014 Thanks Rich, I guess it's what you said because I prefer preloading every game object (even if it's not going to be used yet) on creation so that the game runs smoother later. Link to comment Share on other sites More sharing options...
rich Posted August 4, 2014 Share Posted August 4, 2014 Break it up a bit. What you will find for example is that if you create a mass of objects, or do things which cause texture updates, then you'll get a brief delay while all of that happens. So see if you can do a bit of it during the preload, see if you can perhaps start the game off with something that doesn't require specific timing, for example simply fade an image on for half a second. As long as the image was obtained really early, say via the Boot state, then it will render instantly - and although other tasks may not yet be completed that fade should give you enough time for everything to have settled down a bit. You may even be able to hide it behind something as simple as fading the preloader bar away. mariogarranz 1 Link to comment Share on other sites More sharing options...
mariogarranz Posted August 5, 2014 Author Share Posted August 5, 2014 Thank you very much for your tips, Rich. Will take them into account Link to comment Share on other sites More sharing options...
Recommended Posts