android - AS3 Moving vertical and on a random point -
i have code here should have linked movie clip generated randomly on top of stage. generate randomly not on top. items generated supposed move down , disappear, doesn't.
i making game designed android smartphones..
multitouch.inputmode = multitouchinputmode.touch_point; //create enemies array var enemies:array; enemies = new array(); makeenemies(); moveenemies(); //call function how many enemies want make... function makeenemies():void { var tempenemy:movieclip; //make sure library item linkage set enemy... tempenemy = new enemy(); tempenemy.speed = 20; tempenemy.x = math.random()* 800; tempenemy.cacheasbitmapmatrix = tempenemy.transform.concatenatedmatrix; tempenemy.cacheasbitmap = true; trace("enemy"); addchild(tempenemy); enemies.push(tempenemy); tempenemy.addeventlistener(mouseevent.click, killenemies); } function killenemies(event:mouseevent):void { trace("tap"); } //create enemies array if not have one... //create tempenemy enemy library item if not have one... function moveenemies():void { var tempenemy:movieclip; (var i:int =enemies.length-1; i>=0; i--) { tempenemy = enemies[i]; //rotate enemy between 10-5 degrees tempenemy.rotation += (math.round(math.random()*50-5)); //find rotation , move x position direction tempenemy.x -= (math.sin((math.pi/180)*tempenemy.rotation))*tempenemy.speed; tempenemy.y += (math.cos((math.pi/180)*tempenemy.rotation))*tempenemy.speed; if (tempenemy.x < 0) { tempenemy.x = 0; } if (tempenemy.x > stage.stagewidth) { tempenemy.x = stage.stagewidth; } if (tempenemy.y > stage.stageheight) { //remove enemy enemies array removeenemy(i); //subtract life trace("awwwww"); } } } function removeenemy(idx:int) { removechild(enemies[idx]); enemies.splice(idx,1); }
you should call moveenemies(); every frame, so:
import flash.event.event; addeventlistener(event.enter_frame, onenter_frame); function onenter_frame(e:event):void { moveenemies(); }
also, might idea set type of enemy enemy instead of movieclip
var enemy:enemy = new enemy();
Comments
Post a Comment