0

これは、最初にトリガーされたときに魔法のように機能します。しかしその後は、トリガーされるたびに playerYPos が 8 ずつ増加します。考えられることはすべて試しましたが、理由がわかりません。

var playerYPos = 188;
var playerJumpSpeed = 8;
var playerJumpVelocity = playerJumpSpeed;

function jump(){
    playerYPos -= playerJumpVelocity;

    //Hits top
    if(playerYPos < 40){
        playerJumpVelocity = -playerJumpSpeed;
    }
    if(playerYPos >= 188){
        keyW = false;
    }
}

どんな助けでも大歓迎です!

4

1 に答える 1

0

playerJumpVelocity次回関数が呼び出されたときに変数がリセットされていないためですか?すなわち:

function jump()
{
    var playerJumpVelocity = playerJumpSpeed;
    playerYPos -= playerJumpVelocity;

    //Hits top
    if(playerYPos < 40){
        playerJumpVelocity = -playerJumpSpeed;
    }
    if(playerYPos >= 188){
        keyW = false;
    }
}
于 2013-02-11T21:22:33.040 に答える