0

I'm using Starling framework and Flash Builder.

I have big map image(around 5500x4500px) where player is flying around. It is non repeative, not tile based but vector based.

I'm moving camera around following player on each enterFrame event, camera displays approx 800x400 part of map per frame. Camera movemet is simulated by changing X and Y coordinate of maps parent DisplayObject. What is the best way to draw this and have stable 60fps?

What I have now(attemp with max FPS on mobile):

  • 9 Starling Images with max texture size: 2048x2048(or less on edges). I get 53-60 FPS, but I need stability, I feel like I'm hitting rendering limits already.

What I tried(gives less FPS):

  • Drawing sprites for each seperate map object(much more than 9 but smaller size)

  • Using CullingSprite(not rendering itsel when not visible)

1 Answers1

2

Really you only need 4 images the size of your screen which wrap around and sample from the texture atlas. And for a starling implementation movieclips are great because you can just change its contents to a different frame or portion of the texture atlas. This way you aren't deleting and creating new images every time you need to wrap.

enter image description here

Batching is also one way you can improve on it, moving all samples as a single unit.

Iggy
  • 4,767
  • 5
  • 23
  • 34
  • Great idea about having only 4 screens! Is is ok for fast rendering that screen size is not 2^n? – user1561713 Oct 17 '14 at 23:56
  • So basically I'm still moving container DisplayObject which contains all 4 BGs, but not further than screen.width, screen height, and when I hit the side of those BG container I just jump and change Movieclip images, did I get your advice right? – user1561713 Oct 18 '14 at 00:01
  • Screen size does not have to be 2^n. The only real benefit would be to have your samples 2^n, but that might result in samples being a whole lot bigger because even if you need just a couple more pixels 2^n will double it! – Iggy Oct 18 '14 at 00:03
  • You will still need to check samples wrapping conditions individually (for all 4). However moving them as a single unit does improve the performance. – Iggy Oct 18 '14 at 00:08
  • I looked into Starlings MovieClip. It can't set specific frame. There are some extensions([link](https://gist.github.com/jangarita/2936831)), but they all create some display objects for each frame, then just addChild or removeChild whenever animation advances... So basically I'll have to nest all screensized parts in seperate DisplayObjects and addChild/remoweChild them in order to see only 4 at each moment, right? – user1561713 Oct 18 '14 at 01:11
  • Hm, in that case you might want to use the image class manually because the class you linked to probably does it under the hood anyway (It's an expensive operation). So have a look at [this link](http://doc.starling-framework.org/core/starling/textures/Texture.html), especially the **Texture Frame** part. Cut out texture parts you need and store then in an Image. – Iggy Oct 18 '14 at 01:39