I'm making a tile game in Action Script 3 / Starling.
Suppose I have a scenario like this:
+----+----+----+----+----+
| | | | | | 0th row - highest
+----+----+----+----+----+
| | | | | |
+----+----+----+----+----+
| | | | | |
+----+----+----+----+----+
| | | | | | 3rd row - lowest
+----+----+----+----+----+
In this example, I have a 5x4 tile scenario. In a real gameplay I'll have a 100x100 tile scenario.
This squared map is for an RPG game, where each square could be occupied by an object or a character. Objects can be like trees, which are high and would hide the objects behind.
The key concept here is "hiding objects behind", and the greater is the row number, the "nearest" to the screen it will be, and if the row number is N, rows from 0 to N-1 will be hidden (actually "overlapped") by objects in the layer N (example: if a character is standing on position (x=1,y=2) having a height of 2, and a tree is standing at position (x=1,y=3), the tree would completely overlap the character "above".
I thought about a possible alternative:
If I have the current Starling sprite (which was created by Starling itself passing its class to the Starling constructor), and create one Sprite (sub-sprite) for each row, attaching it to the parent sprite:
private var rows:Vector.<Sprite> = null;
public function createMapRows(nRows:int) {
this.rows = new Vector.<Sprite>();
for(var r:int = 0; r < nRows; r++) {
this.addChild(new Sprite());
}
}
If a character moves left or right, it would remain on the same layer. If a character moves up, I could move the player from the Nth created sprite to the (N-1)th created sprite keeping its (X,Y) coordinates AND performing the 'move up' animation. If a character moves down, I could move the player from the Nth created sprite to the (N-1)th created sprite keeping its (X,Y) coordinates AND performing the 'move down' animation.
I believe this would work but I'm concerned about one aspect: performance.
My Question is: Is this the best way to accomplish this regarding memory performance? Or could be a better solution which does not involve the N+1* problem? (Actually, if the first question has a "NO" answer, I'd like an alternative).
(* No, it's not the N+1 problem regarding database records :p, but amount of sprites).