flash as3,人(hen_mc)在迷宫(walls)中走,怎么实现碰到物体时,跳转到第二帧?
这里是目前已经有的代码:stop();stage.addEventListener(KeyboardEvent.KEY_DOWN,keydown);stage.addEv...
这里是目前已经有的代码:
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN,keydown);
stage.addEventListener(KeyboardEvent.KEY_UP,keyup);
var up = false,down = false,right = false,left = false;
function keydown(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.UP :
up = true;
break;
case Keyboard.DOWN :
down = true;
break;
case Keyboard.LEFT :
left = true;
break;
case Keyboard.RIGHT :
right = true;
break;
}
}
function keyup(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.UP :
up = false;
break;
case Keyboard.DOWN :
down = false;
break;
case Keyboard.LEFT :
left = false;
break;
case Keyboard.RIGHT :
right = false;
break;
}
}
stage.addEventListener(Event.ENTER_FRAME,enterframe);
function enterframe(e):void
{
with (hen_mc)
{
var sp = 10;//sp是移动速度
if (up)
{
y -= sp;
}
if (down)
{
y += sp;
}
if (right)
{
x += sp;
}
if (left)
{
x -= sp;
}
if (walls.hitTestPoint(getBounds(stage).left,y,true))
{
x += sp;
}
if (walls.hitTestPoint(getBounds(stage).right,y,true))
{
x -= sp;
}
if (walls.hitTestPoint(x,getBounds(stage).top,true))
{
y += sp;
}
if (walls.hitTestPoint(x,getBounds(stage).bottom,true))
{
y -= sp;
}
}
} 展开
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN,keydown);
stage.addEventListener(KeyboardEvent.KEY_UP,keyup);
var up = false,down = false,right = false,left = false;
function keydown(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.UP :
up = true;
break;
case Keyboard.DOWN :
down = true;
break;
case Keyboard.LEFT :
left = true;
break;
case Keyboard.RIGHT :
right = true;
break;
}
}
function keyup(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case Keyboard.UP :
up = false;
break;
case Keyboard.DOWN :
down = false;
break;
case Keyboard.LEFT :
left = false;
break;
case Keyboard.RIGHT :
right = false;
break;
}
}
stage.addEventListener(Event.ENTER_FRAME,enterframe);
function enterframe(e):void
{
with (hen_mc)
{
var sp = 10;//sp是移动速度
if (up)
{
y -= sp;
}
if (down)
{
y += sp;
}
if (right)
{
x += sp;
}
if (left)
{
x -= sp;
}
if (walls.hitTestPoint(getBounds(stage).left,y,true))
{
x += sp;
}
if (walls.hitTestPoint(getBounds(stage).right,y,true))
{
x -= sp;
}
if (walls.hitTestPoint(x,getBounds(stage).top,true))
{
y += sp;
}
if (walls.hitTestPoint(x,getBounds(stage).bottom,true))
{
y -= sp;
}
}
} 展开
展开全部
你碰撞的代码都写好了。。。。里面加上gotoAndStop(2)不就可以了吗。。。
if (walls.hitTestPoint(getBounds(stage).left,y,true))
{
x += sp;
gotoAndStop(2) ;
}
if (walls.hitTestPoint(getBounds(stage).right,y,true))
{
x -= sp;
gotoAndStop(2) ;
}
if (walls.hitTestPoint(x,getBounds(stage).top,true))
{
y += sp;
gotoAndStop(2) ;
}
if (walls.hitTestPoint(x,getBounds(stage).bottom,true))
{
y -= sp;
gotoAndStop(2) ;
}
if (walls.hitTestPoint(getBounds(stage).left,y,true))
{
x += sp;
gotoAndStop(2) ;
}
if (walls.hitTestPoint(getBounds(stage).right,y,true))
{
x -= sp;
gotoAndStop(2) ;
}
if (walls.hitTestPoint(x,getBounds(stage).top,true))
{
y += sp;
gotoAndStop(2) ;
}
if (walls.hitTestPoint(x,getBounds(stage).bottom,true))
{
y -= sp;
gotoAndStop(2) ;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询