我已经在这坚持两天了。

我一直在观看这个YouTube教程来制作2D游戏,目前为止在第一部分没有太多问题,但现在在第二部分出现了问题:我无法从地面跳起,但只要不触碰地面,就可以无限次跳跃。

下面是视频:
https://www.youtube.com/watch?v=3bHbydefA8c&list=PL14Yj-e2sgzxXOwdMYC0IDuG9m-VHEMW2&index=2

这是我目前设置的代码:

!&#x200B;!<//获取输入

GetControls()

//X 移动

//方向

moveDir = rightkey - leftkey;

//获取 X 速度

xspd = moveDir * moveSpd;

//X 碰撞

var _subPixel = .5;

if place_meeting ( x + xspd, y, Obj_ground )

{

//精确向上平移到墙壁

var _pixelCheck = _subPixel * sign(xspd);

while !place_meeting ( x + _pixelCheck, y, Obj_ground )

{

    x += _pixelCheck;

}

//将 X 速度设置为零以产生碰撞

xspd = 0;

}

//移动

x += xspd;

//Y 移动

//重力

yspd += grav;

//重置/准备跳跃变量

if onGround

{

    JumpCount = 0;

} else {

    //确保玩家在空中时不能进行额外跳跃

if JumpCount == 0 { JumpCount = 1; };

}







//跳跃



if jumpkeybuffered && JumpCount < JumpMax

{

    //重置缓冲

    jumpkeybuffered = false;

    jumpkeybufferTimer = 0;



    //增加已执行的跳跃次数

    JumpCount++;



    //设置跳跃保持计时器

     JumpHoldTimer = JumpHoldFrames;

}

//根据计时器/按住按钮进行跳跃

if jumpkeybufferTimer > 0

{



//始终设置 Y 速度为跳跃速度

yspd = jspd;

    //计数计时器

     JumpHoldTimer--;

}



//Y 碰撞与移动

//限制下落速度

if yspd > termVel { yspd = termVel; };

//碰撞

var _subPixel = .5;

if place_meeting(x, y + yspd, Obj_ground )

{

    //精确向上平移到墙壁

    var _pixelCheck = _subPixel * sign(yspd);

    while !place_meeting( x, y + _pixelCheck, Obj_ground )

    {

        y += _pixelCheck;

    }



    //将 Y 速度设置为零以产生碰撞

    yspd = 0;

}

//判断是否在地面

if yspd >= 0 && place_meeting( x, y+1, Obj_ground )

{

    onGround = true;

} else {

    onGround = false;

}



//移动

y += yspd;&gt;!&amp;#x200B;!&lt;