The reason for this is, before I was creating an entire world-size bitmap to perform hit-tests against with the character, meaning it would create a 21x16 tile bitmap in memory - so thats 336 tiles it had to copy before even doing the hit test. It would then have to redo this after the hit-test to refresh the screen in the correct location.
In the new version, it creates a mini-bitmap of the tiles surrounding the characters centre point and does the hit-tests on this instead, so instead of 336 tiles being loaded into a large bitmap, only 9 tiles are loaded into a much smaller bitmap.
This of course will have an impact on not only how fast the screen will redraw each frame, but also the hit tests will use far less calculations since it only needs to test the non-transparent pixels in the 3x3 tile mini bitmap, so speed increases all round!
Not only that, but I also changed how the array is created to a way that makes it around 90% quicker to access after creation (something to do with Flash' optimization code) than how I was using it, so overall now the game should be running MUCH faster!
Here is the game now, with the mini bitmap it is performing the hit-tests against in the top left corner (move the character around and you'll see!)
0 comments:
Post a Comment