flash actionscript 3.0 键盘事件 20
我做的是一个龙在随机运动然后一个小球s1在被键盘控制上下左右运动可是龙是挺正常的但s1不被控制是不是和计时器有冲突importflash.utils.Timer;long...
我做的是一个龙在随机运动 然后一个小球s1在被键盘控制 上下左右运动可是龙是挺正常的但s1不被控制 是不是和计时器有冲突
import flash.utils.Timer;
long.gotoAndStop("stop_right");var n:int;
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,f1);
timer.start();
function f1(e:TimerEvent)
{n = Math.floor(Math.random() * 4 + 1);
this.addEventListener(Event.ENTER_FRAME,R2);
}
function R2(e:Event)
{
switch (n)
{
case 1 :
long.gotoAndStop("run_right");
long.x += 3;
if (long.x > 550)
{
ch2();
}
break;
case 2 :
long.gotoAndStop("run_left");
long.x -= 3;
if (long.x < 0)
{
ch2();
}
break;
case 3 :
long.gotoAndStop("run_down");
long.y += 3;
if (long.y > 400)
{
ch2();
}
break;
case 4 :
long.gotoAndStop("run_up");
long.y -= 3;
if (long.x < 0)
{
ch2();
}
break;
}
}
function ch2()
{
timer.stop();
gotoAndStop(3);
this.removeEventListener(Event.ENTER_FRAME,R2);
}
a2.addEventListener(MouseEvent.CLICK,ch1);
function ch1(e:Event)
{
timer.stop();
gotoAndStop(3);
this.removeEventListener(Event.ENTER_FRAME,R2);
}
//const speed:int = 5;
stage.addEventListener(KeyboardEvent.KEY_DOWN,g1);
function g1(e:KeyboardEvent)
{
switch (e.keyCode)
{
case Keyboard.UP :
s1.y -= 5;
break;
case Keyboard.DOWN :
s1.y += 5;
break;
case Keyboard.LEFT :
s1.x -= 5;
break;
case Keyboard.RIGHT :
s1.x += 5;
break;
case Keyboard.SPACE :
s1.y -= 50;
break;
}
}
stage.addEventListener(KeyboardEvent.KEY_UP,g2);
function g2(e:KeyboardEvent)
{
switch (e.keyCode)
{
case Keyboard.SPACE :
s1.y += 50;
break;
}
} 展开
import flash.utils.Timer;
long.gotoAndStop("stop_right");var n:int;
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,f1);
timer.start();
function f1(e:TimerEvent)
{n = Math.floor(Math.random() * 4 + 1);
this.addEventListener(Event.ENTER_FRAME,R2);
}
function R2(e:Event)
{
switch (n)
{
case 1 :
long.gotoAndStop("run_right");
long.x += 3;
if (long.x > 550)
{
ch2();
}
break;
case 2 :
long.gotoAndStop("run_left");
long.x -= 3;
if (long.x < 0)
{
ch2();
}
break;
case 3 :
long.gotoAndStop("run_down");
long.y += 3;
if (long.y > 400)
{
ch2();
}
break;
case 4 :
long.gotoAndStop("run_up");
long.y -= 3;
if (long.x < 0)
{
ch2();
}
break;
}
}
function ch2()
{
timer.stop();
gotoAndStop(3);
this.removeEventListener(Event.ENTER_FRAME,R2);
}
a2.addEventListener(MouseEvent.CLICK,ch1);
function ch1(e:Event)
{
timer.stop();
gotoAndStop(3);
this.removeEventListener(Event.ENTER_FRAME,R2);
}
//const speed:int = 5;
stage.addEventListener(KeyboardEvent.KEY_DOWN,g1);
function g1(e:KeyboardEvent)
{
switch (e.keyCode)
{
case Keyboard.UP :
s1.y -= 5;
break;
case Keyboard.DOWN :
s1.y += 5;
break;
case Keyboard.LEFT :
s1.x -= 5;
break;
case Keyboard.RIGHT :
s1.x += 5;
break;
case Keyboard.SPACE :
s1.y -= 50;
break;
}
}
stage.addEventListener(KeyboardEvent.KEY_UP,g2);
function g2(e:KeyboardEvent)
{
switch (e.keyCode)
{
case Keyboard.SPACE :
s1.y += 50;
break;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询