Friday, 15 March 2013

Starling - squared tile map and positioning -



Starling - squared tile map and positioning -

i'm making tile game in action script 3 / starling.

suppose have scenario this:

+----+----+----+----+----+ | | | | | | 0th row - highest +----+----+----+----+----+ | | | | | | +----+----+----+----+----+ | | | | | | +----+----+----+----+----+ | | | | | | 3rd row - lowest +----+----+----+----+----+

in example, have 5x4 tile scenario. in real gameplay i'll have 100x100 tile scenario.

this squared map rpg game, each square occupied object or character. objects can trees, high , hide objects behind.

the key concept here "hiding objects behind", , greater row number, "nearest" screen be, , if row number n, rows 0 n-1 hidden (actually "overlapped") objects in layer n (example: if character standing on position (x=1,y=2) having height of 2, , tree standing @ position (x=1,y=3), tree overlap character "above".

i thought possible alternative:

if have current starling sprite (which created starling passing class starling constructor), , create 1 sprite (sub-sprite) each row, attaching 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 character moves left or right, remain on same layer. if character moves up, move player nth created sprite (n-1)th created sprite keeping (x,y) coordinates , performing 'move up' animation. if character moves down, move player nth created sprite (n-1)th created sprite keeping (x,y) coordinates , performing 'move down' animation.

i believe work i'm concerned 1 aspect: performance.

my question is: best way accomplish regarding memory performance? or improve solution not involve n+1* problem? (actually, if first question has "no" answer, i'd alternative).

(* no, it's not n+1 problem regarding database records :p, amount of sprites).

one thing create you'r own sprite instance every row or objects of row.

i this:

the base of operations sprite object contains ground tiles cause there under else. , on top of create sprite filled objects row.

clouds row 0 objects row 1 objects row 2 objects <-- player here @ moment row 3 objects baselayer - ground tiles

and, mentioned before, if player goes north or south addchild player sprite right row sprite.

starling-framework

No comments:

Post a Comment