Actionscript 3 试图使主mc跳转,代码赢了';我不能在AS3上工作
我试图做的是让mcMain跳转,但是当我尝试游戏时,我的代码似乎不起作用(尽管我的mc会水平移动)。我被告知尝试在eFrame()函数中运行mainJump()函数。但是,由于我是初学者,我完全不知道这意味着什么(特别是因为英语不是我的第一语言)。如果您能告诉我要添加或更正的内容,我将非常感激!!我的代码是这样的:Actionscript 3 试图使主mc跳转,代码赢了';我不能在AS3上工作,actionscript-3,Actionscript 3,我试图做的是让mcMain跳转,但是当我尝试游戏时,我的代码似乎不起作用(尽管我的mc会水平移动)。我被告知尝试在eFrame()函数中运行mainJump()函数。但是,由于我是初学者,我完全不知道这意味着什么(特别是因为英语不是我的第一语言)。如果您能告诉我要添加或更正的内容,我将非常感激!!我的代码是这样的: var mainSpeed:int = 25; //how fast the character move side to side var mainJumping = false;
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;
}
}
var mainSpeed:int=25//角色左右移动的速度有多快
var=false//不管主管道是否在空中
var跳线速度:数字=0//他现在跳得多快啊
var jumpSpeedLimit:int=25//他能跳多快
addEventListener(Event.ENTER_FRAME,eFrame);
函数eFrame(e:事件):无效{
//使角色跟随鼠标
如果(mouseX>mcMain.x+25){//如果鼠标位于mcMain的右侧
mcMain.x+=mainSpeed;//将mcMain移到右侧
}如果(mouseX-jumpSpeedLimit*.1){//如果jumpSpeed足够小
跳跃速度*=-1;//然后开始下降
}
}
如果(跳线速度>0&&跳线速度=387.5){
main=false;
mcMain.y=387.5;
}
}
如果(mcMain.y>387.5){
mcMain.y=387.5;
}
}
您的问题是,您从未在mainJump
函数中实际运行代码。这一行:
addEventListener(Event.ENTER_FRAME, eFrame);
确保每帧都运行eFrame
函数,但它没有说明何时运行mainJump
函数。幸运的是,您可以从eFrame
函数中调用mainJump
函数,如下所示:
function eFrame(e:Event):void {
// ... original code ...
mainJump();
}
这将在每一帧运行
mainJump
功能,因此它应该允许您的播放器跳转。谢谢,解释得非常清楚!!从现在起我会记住这个!!