[问题] 发射子弹间隔失败~~求解

楼主: mucoci (奇宝~)   2013-12-02 21:07:07
小弟要作出 机体在射出子弹后,隔三秒才能再发射
由监听鼠标click 开始
完成后
一开始的确正常
但过一会儿如果连点鼠标后,就失常了
变成可以连发@@"
隔三秒的限制不见了~~
请各位高手协助看一下是哪的问题~
程式码如下
//监听鼠标点击来发射子弹
nowthis.stage.addEventListener(MouseEvent.MOUSE_DOWN,BulletEvent);
function BulletEvent(me:MouseEvent):void
{
if (MouseEvent.CLICK && canfire == 1) //变量canfire用来控制是否可发射
{ 1可发射,2不可发射
canfire =2; //可发射后,立刻让接下来变不可发射
并移除鼠标点击的监听
stage.removeEventListener(MouseEvent.MOUSE_DOWN,BulletEvent);
//当鼠标按下时,在场景上创造一个子弹
var ball_mc =new ball();
  //设定子弹出现时的起始座标,正常来说应该是要设定在子弹的砲口处
ball_mc.x=nowthis['warcarshooter_mc'].x;
ball_mc.y=nowthis['warcarshooter_mc'].y;
//这里是设定子弹行进的位移速度,分别计算出来并且写入子弹的属性内
  //属性名称可以自己定
ball_mc.MoveX=carbulletspeed/30*Math.cos((nowthis['warcarshooter_mc'].rotation-90)*Math.PI/180);
ball_mc.MoveY=carbulletspeed/30*Math.sin((nowthis['warcarshooter_mc'].rotation-90)*Math.PI/180);
ball_mc.rotation=nowthis['warcarshooter_mc'].rotation-90;
nowthis.addChild(ball_mc);
//赋予子弹一个ENTER_FRAME的事件
ball_mc.addEventListener(Event.ENTER_FRAME,BulletMoveEvent);
//下面是在3秒后,变可射击状态,同时加回鼠标监听
setInterval(function ()
{
canfire = 1;
stage.addEventListener(MouseEvent.MOUSE_DOWN,BulletEvent);
}, 3000);
}
}
感谢~~
作者: emily114005 (瑷幂瑮)   2013-02-03 08:51:00
clearInterval

Links booklink

Contact Us: admin [ a t ] ucptt.com