Manifest Posted April 10, 2014 Share Posted April 10, 2014 When I add a sprite to the screen there is often a sizeable delay before it appears, especially if it's on mobile and it's a large sprite(sheet). I've seen upwards of 800ms delay per sprite on some mobile devices. This delay seems to be the initial tex2D draw call, where I suspect it uncompresses the image or caches it or something similar - subsequent appearances of the same sprite do not have the same long delay. Note: I have a loading screen where the asset is loaded into the Phaser.game.cache already, so that is not occurring during gameplay. This is causing me to run into issues when I want to animate something immediately upon adding it to the screen. My code should behave roughly like:Add sprite to screen Sprite gets added to screen Animate sprite with initial appearance animation (~ 1 second duration)But instead, due to the appearance delay, it works something like:Add sprite to screen sprite.animations.play() *DELAY* Sprite finally visible onscreen, no animation plays (sprite remains in frame 0)It's as though the sprite "misses" the animations.play() call as it hasn't finished caching or whatever it's doing. What I really want to do is something like:Add sprite to screen sprite.events.onActuallyLoadedForReal.addOnce(() => sprite.animations.play());To mitigate the problem, I have tried:Saving the sprite as an uncompressed .png to cut down on delay time Preloading the sprite i.e. showing it on the main menu where interaction is not critical Putting in a Phaser.Timer before I call animations.play() and hoping that it has finished Options 2 & 3 prevent the issue, but are not ideal solutions. my question is basically: is there a better way to do this, or is there a way that events.onActuallyLoadedForReal could actually be listened for? Link to comment Share on other sites More sharing options...
rich Posted April 11, 2014 Share Posted April 11, 2014 Hmm I've never seen this happen before, but I guess it may take a while to upload to the GPU - 800ms seems ridiculously excessive though, even for a really slow GPU. Here's a thought - after your preloader, why not create a sprite using the texture then? Set alpha to 0 or something so it doesn't render, or hide it off-screen, but at least the texture will then be on the GPU. Needless to say there is no event you could ever listen to in order to find out when this happens, because it's impossible for JavaScript to know when a texture is on the GPU or not. Link to comment Share on other sites More sharing options...
Manifest Posted April 13, 2014 Author Share Posted April 13, 2014 Thanks rich, yeah, I suspected there would be no way to tell. I'm currently using the approach you suggested and trying to hide the lag spikes on screens where smooth framerate isn't a priority, but it's not ideal. Link to comment Share on other sites More sharing options...
rich Posted April 14, 2014 Share Posted April 14, 2014 Just to reiterate - I've never seen what you're describing happen, not across loads of testing devices and different frameworks - which makes me wonder just how large your sprite sheets are, and how flooded the GPU memory has become. Link to comment Share on other sites More sharing options...
Manifest Posted April 14, 2014 Author Share Posted April 14, 2014 The spritesheets are around 2500x2500px, uncompressed they make up about 92MB total. Nexus 10 is one of our target devices, so high resolution is a priority. Link to comment Share on other sites More sharing options...
rich Posted April 14, 2014 Share Posted April 14, 2014 Wow, that's a lot of data. 92MB uncompressed, you mean actual GPU RAM size, or just uncompressed file size? Link to comment Share on other sites More sharing options...
Manifest Posted April 14, 2014 Author Share Posted April 14, 2014 Just uncompressed filesize. Yeah, it's a lot =/ Link to comment Share on other sites More sharing options...
rich Posted April 14, 2014 Share Posted April 14, 2014 Blimey, that must be hundreds of MB of actual GPU ram. I wonder how much is even made available to the browser on a Nexus 10, once the OS and other running apps and tabs have taken their slice. Link to comment Share on other sites More sharing options...
richpixel Posted April 17, 2014 Share Posted April 17, 2014 Btw I'm also dealing with a similar issue - I load my assets and show a background image of 768x1104 (usually cropped height). Then I put a single animated sprite on top and the first few frames chug at a low frame rate before it 'catches' and starts playing smoothly. I only see the issue on slower/older devices like iPhone 4. However, the issue goes away if I don't show the background image. I figure there is some way to juggle this where you display sprites initally offscreen or hidden in some way to ensure textures are in the GPU before I really need them. Still investigating. Manifest 1 Link to comment Share on other sites More sharing options...
Recommended Posts