actionscript 3 - AS3: Separate instances in an array? -
i'm making side scrolling game in as3, player spawns units automatically walks towards exit on other side of screen, there towers stopping them. towers shoot separately, there way? here's code, once if statements satisfied towers fire @ same time.
private function tower1fire():void { (var j:int = creep1array.length - 1; j >= 0; j--) { each (var towerone:mctower1 in tower1array) { if (creep1array[j].x - towerone.x <= 100 && creep1array[j].y > towerone.y) { var newtower1bullet:mclaser1 = new mclaser1; newtower1bullet.x = towerone.x; newtower1bullet.y = towerone.y; tower1bulletarray.push(newtower1bullet); stage.addchild(newtower1bullet); } } } }
i have 3 towers on screen, added using code:
var tower1new1:movieclip = new mctower1; tower1new1.x = 313; tower1new1.y = 340; tower1array.push(tower1new1); movieclip(root).addchild(tower1new1);
i don't error. reply appreciated, thanks!
from can tell, of towers going 'fire' in single 'frame render', why looks firing @ once. (because whole loop going execute within single draw operation)
if we're you, listen enter_frame event, , keep count of frames.... fire single tower only, once 10-20 frames. so...
private enter_frame(event:event):void { if(framecount >= 20) { // todo: fire logic goes here // reset framecount 0 framecount = 0; // need keep running index of towers, // next time code executes, fire next tower towerindex++ } framecount++; }
so, if we're way, wouldn't have loop.
Comments
Post a Comment