jomdarbert Posted March 9, 2015 Share Posted March 9, 2015 deleted jomdarbert 1 Link to comment Share on other sites More sharing options...
Matthew Cooley Posted March 10, 2015 Share Posted March 10, 2015 It will be difficult to help without understanding what you are doing technically. My experience with Phaser is small, but some problems are common among many platforms. Off the top of my head, there are a few things I would look at: - touch/mouse events: are each of these tiles carrying a touch/mouse event? For thousands of sprites, that might be an issue. Especially if you are using a grid, don't set the interactive to all the sprite to true, and instead calculate which sprite was touch/clicked based on the cursor/mouse xy position. - are you using many different textures? Phaser/Pixi can render thousands of Sprites very well, but as the variety of textures increase, the performance can take a big hit. - do each of these tiles have their own loops and complicated logic executed every frame? If so, are you using a shared prototype object for these functions? These costs are small but can add up when you have 1000+ instances. The best thing to do would be to use a performance profiler, like the one in Chrome. In Chrome, open View > Developer > Developer Tools, and select 'Profiles'. Start a new profile, play your game, then stop the profile. It will give you a report on which functions are taking the longest to complete. This is actually pretty fun, and you can learn a lot of things you weren't expecting to digging around in the profiler report. If you are not sure what you are looking it, post the results here. Link to comment Share on other sites More sharing options...
jomdarbert Posted March 10, 2015 Author Share Posted March 10, 2015 Hey Matthew, thanks for the response! - touch/mouse events: are each of these tiles carrying a touch/mouse event? For thousands of sprites, that might be an issue. Especially if you are using a grid, don't set the interactive to all the sprite to true, and instead calculate which sprite was touch/clicked based on the cursor/mouse xy position. The bold portion above is what I am currently doing. - are you using many different textures? Phaser/Pixi can render thousands of Sprites very well, but as the variety of textures increase, the performance can take a big hit. My atlas currently has 8 textures total, and the sprite atlas is 48kb in size. - do each of these tiles have their own loops and complicated logic executed every frame? If so, are you using a shared prototype object for these functions? These costs are small but can add up when you have 1000+ instances. The tiles themselves do not have any logic - they are merely storehouses for various properties. They are built from the same class prototype. I have several handlers (e.g. unitHandler, jobHandler, etc.) that perform the game logic instead - really all I'm using phaser for is to render the objects on screen and to tween them around. The best thing to do would be to use a performance profiler, like the one in Chrome. In Chrome, open View > Developer > Developer Tools, and select 'Profiles'. Start a new profile, play your game, then stop the profile. It will give you a report on which functions are taking the longest to complete. This is actually pretty fun, and you can learn a lot of things you weren't expecting to digging around in the profiler report. If you are not sure what you are looking it, post the results here. Great idea! I did this just now - results here. It looks like most CPU cycles are being used by "Phaser.Sprite.preUpdate", "PIXI.DisplayObjectContainer.updateTransform", "PIXI.DisplayObject.updateTransform", and "PIXI.WebGLSpriteBatch.render". Thanks again! Link to comment Share on other sites More sharing options...
Matthew Cooley Posted March 11, 2015 Share Posted March 11, 2015 I think 8 textures should not be too much. However, it is not the file size but the pixel dimensions that would contribute to performance issues. I don't know what the sweet spot is for phaser/canvas/webgl. Those numbers being allocated to phaser for rendering are really high. Ideally you want the highest % of all processes to be 'idle', not a render call. There is definitely a bottleneck somewhere, either the speed of your computer or something in your code. Keep using the profiler, and try some experiments one at a time; turning things on and off and tinkering with Phaser and Sprite settings that could affect performance (there are probably a number of these, you will have to look at the Phaser docs to learn more). But first try using a single, simple texture for all these sprites (like 64x64 pixels). If the performance increases dramatically, your bottle neck is probably texture-related. Also, make sure you don't have a bunch of other browser windows open running WebGL. Other versions of your game, other peoples games, phaser examples, etc... If you have other applications hogging up the GPU, the slowdown may have nothing to do with your game at all. See if other Phaser games with similar complexity are also running really slow for you. Link to comment Share on other sites More sharing options...
Recommended Posts