【发布时间】:2014-02-07 23:39:19
【问题描述】:
问题很明确。角色在舞台上稳定,背景和地面在移动。但是当角色落地时,它会一次又一次地弹跳。这是代码。我该如何解决?当我移动角色时,它的工作很完美,但是当移动物体是地面弹跳问题时会发生。 这是问题所在:http://www.swfcabin.com/open/1391814250
public function controller():void
{
if (rightKey || leftKey || jumpKey)
{
if (rightKey)
{
if (jumpWalk || canJump)
{
hero.gotoAndStop(2);
hero.scaleX = 1;
xSpeed -= speed;
}
}
if (leftKey)
{
if (jumpWalk || canJump)
{
hero.gotoAndStop(2);
hero.scaleX = -1;
xSpeed += speed;
}
}
if (jumpKey && canJump)
{
ySpeed += 15;
canJump = false;
}
}
else
{
hero.gotoAndStop(1);
}
if(!canJump){
hero.gotoAndStop(3);
}
ySpeed -= gravity;
if(ySpeed >10){
ySpeed = 10;
}
else if(ySpeed < -10){
ySpeed = -10;
}
if(xSpeed>10){
xSpeed = 10
}
else if(xSpeed < -10){
xSpeed = -10;
}
xSpeed *= 0.8;
level.x += xSpeed;
level.y += ySpeed;
}// controller function
public function loop(event:Event):void
{
controller();
while(level.hitTestPoint(hero.x , hero.y + hero.height/2 -1 - ySpeed , true)){
trace(ySpeed +"dasd");
ySpeed ++;
canJump = true;
} }
【问题讨论】:
-
你能制作一个关于发生了什么或什么的 GIF 吗?我真的无法想象这应该是什么样子。
-
这里是 .swf:swfcabin.com/open/1391814250
-
嗯,你能给我们看一段
trace(ySpeed)输出的内容吗?
标签: actionscript-3 platform hittest