dgamma3
dgamma3

Reputation: 2371

AS3 - game - concept recommendation

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

Answers (2)

ncreated
ncreated

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

Marty
Marty

Reputation: 39456

  1. Add the game content (including player) into a container.
  2. 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:

  1. The container is moved to negative x:120 and negative y:100. This causes the player to appear in the top left of the stage.
  2. The container is then shifted half the stage width across and half the stage height down, positioning the player in the centre of the screen.

I've done a quick example that can be found here: http://junk.projectavian.com/env.zip

Upvotes: 3

Related Questions