Reputation: 2371
Ok, so I'm building a space game. Image the stage is 500 by 500, however the actual map is a lot bigger i.e. 4000 by 4000. as you move your spaceship (which is centered) you move around the (4000by 4000 px) map.
I am using both flash IDE and flash develop.
what is the best way to achieve this. Tutorial links would be appreciated.
thanks, daniel
Upvotes: 1
Views: 194
Reputation: 641
With this case I would use blitting technique to optimize such big bitmap rendering. Take a look at this tutorial: Tutorial on Fast Photo Scrolling for the iPad. It shows how much can you gain with using copyPixels() method instead of depending on display list. The idea is similar to what @Marty said, but it uses faster rendering method.
Upvotes: 1
Reputation: 39456
Position the container as per this formula:
x = -player.x + stage.stageWidth / 2;
y = -player.y + stage.stageHeight / 2;
You'll notice that the player is always centred on screen regardless of the position of the player.
Overview:
Assume your player is at position: x:120
y:100
. The above will move the container to be positioned as per these steps:
x:120
and negative y:100
. This causes the player to appear in the top left of the stage.I've done a quick example that can be found here: http://junk.projectavian.com/env.zip
Upvotes: 3