Copy link to clipboard
Copied
I have a game whereby a player character walks around a 2d isometric map. The maps are roughly 30x30 cells in size. Each cell is likely to have it's own floor tile, perhaps a wall tile and sometimes other objects such as rocks, plants etc (some of which are animations). At the moment, each element is loaded from an external .swf and added to the display list in a certain order. The problem I'm having is if a lot of elements (3/400+) are on the screen, my game lags horribly. (It's better with cacheAsBitmap = true, but I want to allow zooming in and out - which then becomes very very slow)
I believe the reason for this is that my display list can have several thousand items in the display list. (With my current design, each externally loaded .swf is nested inside a Sprite)
I am therefore wondering if blitting would help performance and if it would be feasible, considering a few things:
- Is it ok to work out which bitmaps are currently visible, copy the bitmap data and draw everything on each frame. i.e. in an Event.ENTER_FRAME listener? Or can you only really afford to do this for animations
- I would like to be able to click on certain irregularly shaped elements by adding MouseClick listeners. I'm guessing I can get the coordinates of the mouse click and use the bitmapData I have to calculate hit tests?
- what about sprites with filters i.e. GlowFilter
Copy link to clipboard
Copied
That are a lot of Questions 😉
I believe the reason for this is that my display list can have several thousand items in the display list. (With my current design, each externally loaded .swf is nested inside a Sprite)
instead of creating/destroying sprites you should look into object pooling, creating objects is expensive
I am therefore wondering if blitting would help performance
If with blitting you mean: using a TextureAtlas in combination with a framework like Starling: yes
Consider using a specilaized framework like
http://code.google.com/p/as3isolib/
if you are more interested in getting things done, because building a performant 2.5d Engine from the ground up is a lot of work
Copy link to clipboard
Copied
If you're going to do this, keep in mind that copyPixels() is more performant than draw(), so when I've done this, I've created the Bitmaps up front and simply copied the pixels from them every time I needed to update the display.
You might possibly want to take the approach of representing each object in your game as data, and then determining the hit based on this data object that you're moving around in data space. You'll need that anyway to be able to draw the current state of the game.
You can apply a filter to a BitmapData while drawing it.
You may want to also consider a hybrid strategy, where you draw the background as a BitmapData, but keep some other objects as sprites (possibly sprites containing blitted objects).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now