我在让我的 Player 在 AS3 中跳转时遇到问题。我会上传所有相关的东西,我真的很难弄清楚我做错了什么。它曾经可以工作,但现在不行了,我花了很长时间修复错误,我无法弄清楚这是哪里搞砸了。Player 类是从 BoundaryObject 类扩展而来的。我知道该功能已被激活,因为播放器的this.gotoAndStop("jump");
作品。
播放器类 - 跳转功能
public function startJumping():void
{
if (isJumping == false)
{
isJumping = true;
this.gotoAndStop("jump");
downwardVelocity = -28;
}
}
BoundaryObject 类 - 重力的变量/循环
public var downwardVelocity:Number;
protected var isRunning:Boolean;
public var isJumping:Boolean;
public function BoundaryObject()
{
trace("i am any object that collides with the boundary");
downwardVelocity = 0;
isRunning = false;
this.gotoAndStop("jump");
addEventListener(Event.ENTER_FRAME,enterFrameHandler);
// constructor code
}
private function enterFrameHandler(event:Event):void
{
downwardVelocity += 2; //equals itself plus 2
this.y += downwardVelocity;
}
public function incrementUpward()
{
//increment the y up until not colliding
this.y -= 0.1;
}
public function keepOnBoundary()
{
downwardVelocity = 0;//stops pulling the object down
}