我想要做的是让 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;
}
}