Jump to content

The number of layers created in tiled is responsible for poor scrolling performance - why ?


valueerror
 Share

Recommended Posts

my game map is 200x20 tiles big - i have 7 layers.. most of them have only a few tiles on them except the mainlayer and the icelayer which contain the ground ..

 

the moment the camera starts scrolling with my player (follow player) the performance drops to 30 frames/second.

 

 

 

if i comment out all layers except the mainlayer and the icelayer  (so 2 instead of 7 layers)  the performance is top !!

 

 

why is that?  i thought the layers are being converted to p2 bodies and then handled as bodies??  touching tiles should be converted to one single body so performance would be even better..

 

it is definitely not the sheer number of p2 bodies because i created a special test-map (huge with hundreds of independent tiles on one single layer) and the performance was still top..

 

so scrolling my almost empty layers at the cost of 30 fps ??  is this a bug ?

Link to comment
Share on other sites

canvas (no problem with webgl in terms of performance - just rendering problems that's why i stick to canvas - for now) 

 

game 800x640  px

map 200x20  tiles

tiles  32x32 px

 

i just don't get it ..  when scrolling one layer with 1000 tiles is really fast.. why is scrolling 6 layers with 500 tiles slow..  

 

here is a screenshot of one map-example..  what you see are the tiles on the layers i commented out to gain the needed performance...

post-6912-0-45356000-1399552940_thumb.jp

Link to comment
Share on other sites

Are you sure it isn't something more specific about the content of your layers or your scrolling code?  

 

I just did a quick test.  My test map is 80x60 tiles with tiles that are 64x64 pixels.  I created 6 layers.  The layers have very few tiles filled in except for one of them.  I did not notice any change in performance with the extra layers. I'm using chrome with the game configured to use canvas.

 

Do you have debug turned on?

Link to comment
Share on other sites

first of all.. you're right..  at this moment i'm not able to definitely say "the number of layers is responsible"  it could still be something that happens on one of my layers..  i'm going to investigate that first by testing each layer seperately..

 

but..  it's perfectly normal that you didn't see any performance regression..  on 80% of my computers at work my game would run at 60fps straight (sometimes even more :blink: )   but unfortunately or..  luckily my own machine suffers from age (and maybe bad drivers) and there is a drop of 20 to 30 frames on scrolling the canvas with all the layers..  

 

i already tested without the objects layer and without all my "createFromObjects" objects and polygons (hills and so on).. so this is not responsible for the drop.. 

 

i'll investigate further and report here  :)

Link to comment
Share on other sites

ok..  i played around with the layers and now i can say the following..  

 

each of the almost empty layers removed accounts for about 5 fps..  in other words .. every deleted layer gives me back 5 more fps!  (the order doesn't matter.. i tried to shuffle the removal several times ^^)

 

if i remove one of the 3 bigger layers, for example the background layer, (big means more tiles on the grid) this layerremoval gives back up to 7 frames..    i do nothing with this layer.. no collision no whatsoever..  just some trees and hills in the background...

----------------------

oh and for testing this there is another bit of information..  

chromium on linux is in the  #ignore-gpu-blacklist  therefore the performance is on the lower end here.. if i tell chromium to override this list (in chrome://flags)  and use the gpu anyways the performance loss caused by the layers is reduced to almost nothing (-4 fps max)  

 

but i think it's still not ok that scrolling some empty layers uses so much resources

Link to comment
Share on other sites

hey rich.. any news on that? i don't think that anything special only i do in my code is responsible ... is this considered as normal and every pc/browser needs to support gpu rendering to have a smooth experience or is there something one can do about it?  

Link to comment
Share on other sites

I am not really sure why you need 7 layers to render your game.

 

I mean, I understand a background (but that's only an image) then maybe one layer for background objects and one for foreground objects... what are all the other layers for?

 

If they just hold information (where you can climb etc) they shouldn't be layers at all.

(In the sense that there should not be screensized-sprites for them that need to be checked everytime the camera moves, they can be layers in tiled, but if they are not rendered then the data should be accessed in a different way. - Not exactly sure how I must admit).

 

But maybe I didn't understand it correctly.

Link to comment
Share on other sites

well...   first of all i don't think that the solution to this should be a workaround..  not using layers (or using less layers) seems to me as a workaround .. every layer would still slow down everything more than expected. but if there were only 2 or 3 no one would care...

 

those objects on the layers (as you can see in the screenshot in a post above for example) are not very much..  if they were all on the same layer they wouldn't matter at all (i tested it) - they had no influence on performance whatsoever..  afaik they are being converted to p2 bodies and/or pixi textures or something else anyways so the layer shouldn't count anymore...

 

 

working with different layers for, main-ground, ice-ground, enemytiles, enemyboundaries (hidden), ropes (hidden), fore-, background, and objects (enemies, polygons)  is perfect for the level designer..  i do not have to worry about indexes.. he can totally change the complete tileset, change what counts as rope for example, place new stuff on the enemylayer  etc. etc.

as long as he works with the given layers everything will work just fine.. its sort of a framework  

 

the question remains..  

i have 3 to 4 tilesprites spanned over the whole world (6400x640) moving in different speeds related to the camera (parallax) and those do exactly nothing to the performance.. 

 

why is scrolling almost empty layers (even without physics bodies) so performance hungry..   

Link to comment
Share on other sites

i made an extensive test example where you can switch between different amounts of layers ... and for the sake of the test also try all layers merged to one layer..

 

 http://test.xapient.net/phaser/ALL/layers.html

 

 

there you can see that i'm doing nothing with the layers.. they act as backgrounds - nothing else

up to 4 layers it's quite ok (~50fps) but then the performance drops to 35 fps

 

 

i'm going to add an issue on github :)

Link to comment
Share on other sites

https://github.com/photonstorm/phaser/issues/839  github issue

 

 

@ip91   yes .. it gives me very much flexibility and i know that seven layers are quite a lot..   if there is no other way i will reduce the amount of layers anyways but i think there could be a bigger problem with scrolling layers and if there is something that could be done about it it's better for all of us.. even when we need only 4 layers they still eat up performance... (and maybe more than they actually should)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...