Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function to load the enemies to the stage
- public function loadEnemies ():void
- {
- //load in the enemies
- var positions:Array = new Array ();
- data = layout.layer [2].data;
- positions = data.split (",");
- var counter:int = 0;
- var endLoop:int = positions.length;
- var enemy:Enemy;
- var tileValue:int = 0;
- var xpos:int = 0;
- var ypos:int = 0;
- while (counter < endLoop)
- {
- tileValue = positions [counter];
- if (tileValue > 0)
- {
- // modulus operator
- //x position is determined by using the modulus to get the remainer of the layout width.
- //this determines if the xpos needs to move down on the ypos.
- //counter divided by the map width (example 0 / 1 = 0 ) multiplied by tile width ( 0 * 32 == 0)
- // xpos would be 0 then
- //
- xpos = (counter % layout.@width) * layout.@tilewidth;
- //math.floor drops the number down to the lower value (3.6 becomes 3)
- ypos = Math.floor (counter / layout.@width) * layout.@tileheight;
- enemy = new Enemy (tileValue);
- enemy.x = xpos;
- enemy.y = ypos;
- world.add (enemy);
- trace (xpos);
- trace (ypos);
- trace ("stuff");
- }
- counter = counter + 1;
- }
- }
Add Comment
Please, Sign In to add comment