0

私がやろうとしているのはmcMainをジャンプさせることですが、ゲームを試してみるとコードが機能しないようです(ただし、mcは水平方向に移動します)。mainJump()関数をeFrame()関数で実行するように指示されました。しかし、私は初心者なので、それが何を意味するのかまったくわかりません(特に英語は私の母国語ではないため)。何を追加または修正するか教えていただければ幸いです!! だから私のコードは次のようになります:

var mainSpeed:int = 25; //how fast the character move side to side
var mainJumping = false; //whether or not main is in the air
var jumpSpeed:Number = 0; //how quickly he's jumping at the moment
var jumpSpeedLimit:int = 25; //how quickly he'll be able to jump

addEventListener(Event.ENTER_FRAME, eFrame);

function eFrame(e:Event):void{
    //making the character follow the mouse
    if(mouseX > mcMain.x + 25){ //if the mouse is to the right of mcMain
        mcMain.x += mainSpeed;//move mcMain to the right
    } else if (mouseX < mcMain.x - 25){//same thing with the left side
        mcMain.x -= mainSpeed;
    } else {
        mcMain.x = mouseX;//if it's close enough, then make it the same x  value
    }
}


stage.addEventListener(MouseEvent.CLICK, startJump);//if the user clicks

function startJump(e:MouseEvent):void{//then run this function
    if(!mainJumping){//main isn't already jumping
        mainJumping = true;//then we can start jumping
        jumpSpeed = jumpSpeedLimit*-1;//change the jumpSpeed so that we can   begin jumping
    }
}

function mainJump():void{
    if(mainJumping) {//if jumping has been initiated
        if(jumpSpeed < 0){//if the guy is still going up
            jumpSpeed *= 1 - jumpSpeedLimit/120;//decrease jumpSpeed slightly
            if(jumpSpeed > -jumpSpeedLimit*.1){//if jumpSpeed is small enough
                 jumpSpeed *= -1;//then begin to go down
            }
        }
        if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){//if main is going down
            jumpSpeed *= 1 + jumpSpeedLimit/120;//incrase the falling speed
        }
        mcMain.y += jumpSpeed;//finally, apply jumpSpeed to mcMain
        //if main hits the floor, then stop jumping
        if(mcMain.y >= 387.5){
            mainJumping = false;
            mcMain.y = 387.5;
        }
    }
    if(mcMain.y > 387.5){
        mcMain.y = 387.5;
    }
}
4

1 に答える 1

0

ここでの問題は、mainJump関数内で実際にコードを実行していないことです。この行:

addEventListener(Event.ENTER_FRAME, eFrame);

関数がすべてのフレームで実行されることを保証しeFrameますが、いつ関数を実行するかについては何も言いませんmainJump。幸いなことに、次のようにmainJump関数内から関数を呼び出すことができます。eFrame

function eFrame(e:Event):void {
    // ... original code ...
    mainJump();
}

mainJumpこれにより、フレームごとに関数が実行されるため、プレーヤーがジャンプできるようになります。

于 2012-12-23T18:13:32.003 に答える