views:

1112

answers:

3

I'm creating a 2D multiplayer game in a space environment in flash (actionscript 3 with flex builder 3). The player's character (a ship) will always be in the center. Because it has to look like the ship is moving, while it is actually always in the center, the background and all environmental objects have to move the opposite way.

My thought on how to do this would be to create an array with references to all objects in the environment. These will then be looped and their position will be changed in the opposite direction of the ship's movement.

I am however afraid that this will not look smooth, or will be too slow. It will probably cause "stuttering"? Because of that, before I start developing such system, I would like to know if there are better options - or if anyone has experience with what I want to do.

Thanks in advance.

+1  A: 

no, that's the most efficient approach ... and hide all items, that are not on screen, to save performance ... if those object only move, than you should consider flash.display.DisplayObject::cacheAsBitmap, for better performance ...

the alternative would be, to put all items into one Sprite, mask it, and then move around the Sprite ... this will only work properly if your world is limited ... and will only perform ok, if it is small ... so i guess, it's no option ...

back2dos
Quote from the doc: "The cacheAsBitmap property is best used with movie clips that have mostly static content and that do not scale and rotate frequently." - unfortunately, my objects do rotate a lot.
Tom
A: 

Well, you will need to keep track of all of the objects, but you should only have to actually worry about a small amount of them at any given time.

One simple way of doing this would be to divide your play area into a grid of quadrants (how many you end up using will be up to you). A single quadrant could contain multiple different display elements. Then you just have to figure out which square your ship is located in. From that you can figure out the minimum number of quadrants you need to scan through draw the area around the ship.

As elements move around the play area you just need to make sure that they constantly update which quadrant they are located within.

Branden Hall
A: 

As it is a multiplayer game, Branden Hall's approach is much more suited to your needs, as you could easily send notification of the existance of another ship in the surrounding of the player (it's better than giving the user the information of all the non-onscreen elements of their surrounding) I will just add that, depending on the size of your viewport, the number of quadrants on screen could vary, you should always check your current quadrant's boundries to see if adyacent quadrants are being displayed on the viewport.

ONi