一个下午什么也搞不成,只是个跳跃的算法都搞死了,as2.0 就可以,但一换到as 3.0 就失败,好麻烦。算了 还是不管理。 只是可以跳跃少少,总算有些成果了,搞点这个后就可以继续去设计了。
function move(vx:Number, vy:Number):void
{
man.x=man.x + Math.cos(rotation * Math.PI/ 180) * vx;
man.y=man.y + Math.sin(rotation * Math.PI / 180) * vx;
if (!map.hitTestPoint(man.x, man.y + vy, true))
{
man.y=man.y+vy;
}
}
var can_jump:int=0;
var vy:Number=0;
man.addEventListener(Event.ENTER_FRAME,jumping);
function jumping(event:Event):void{
stage.addEventListener(KeyboardEvent.KEY_DOWN,down);
function down(event:KeyboardEvent){
if(event.keyCode==Keyboard.SPACE && can_jump==0)
{ vy=-10;
trace(" jump");
can_jump=1;
}
if(event.keyCode==Keyboard.RIGHT)
{
move(0.5, 0);
}
if(event.keyCode==Keyboard.LEFT)
{
move(-5, 0);
}
}
if(can_jump==1)
{
move(0, -5);
move(0, vy++);
trace(vy);
if (vy >21)
{
can_jump= 0;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////写法二
function move(vx:Number, vy:Number):void
{
man.x+= Math.cos(man.rotation * Math.PI/180) * vx;
man.y+= Math.sin(man.rotation * Math.PI/180) * vx;
if (!map.hitTestPoint(man.x, man.y + vy, true))
{
man.y=man.y+vy;
}
}
var can_jump:int=0;//是否跳了
var vy:Number=0;
man.addEventListener(Event.ENTER_FRAME,jumping);
stage.addEventListener(KeyboardEvent.KEY_DOWN,down);
function down(event:KeyboardEvent){
switch(event.keyCode)
{
case Keyboard.UP:
if(can_jump==0)
{
vy=-10;
can_jump=1;
}
break;
case Keyboard.LEFT:
move(-5, 0);
break;
case Keyboard.RIGHT:
move(5, 0);
break;
default :
break;
}
}
function jumping(event:Event):void{
if(can_jump==1)
{
move(0, -5);
move(0, vy++);
trace(vy);
if (vy ==15)
{
can_jump= 0;
}
}
if (1)
{
move(0, 5);
} }
只可以实现 上跳的效果 ,但不知道为什么不可以前的,奇怪死了。郁闷死了