Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3跳跃(飞行)问题_Actionscript 3 - Fatal编程技术网

Actionscript 3 AS3跳跃(飞行)问题

Actionscript 3 AS3跳跃(飞行)问题,actionscript-3,Actionscript 3,我到处找了找,但找不到一个可以接受的答案。我可能找得不够仔细。我已经离开学校一年了,我在课堂上偶然发现了一个我们制作的flash游戏。我试图修复一些我犯的错误,使它正常工作。我遇到的问题是一个跳跃问题:角色可以无休止地跳跃,就像它在天空中飞翔一样。下一个错误是除非玩家在空中,否则攻击图形不会播放。我对编码已经生疏了,我希望回到as3并使用flash程序。我有一个“player.as”文件,我将把它的代码粘贴到下面。 感谢您的帮助,提前谢谢 package { import flash.dis

我到处找了找,但找不到一个可以接受的答案。我可能找得不够仔细。我已经离开学校一年了,我在课堂上偶然发现了一个我们制作的flash游戏。我试图修复一些我犯的错误,使它正常工作。我遇到的问题是一个跳跃问题:角色可以无休止地跳跃,就像它在天空中飞翔一样。下一个错误是除非玩家在空中,否则攻击图形不会播放。我对编码已经生疏了,我希望回到as3并使用flash程序。我有一个“player.as”文件,我将把它的代码粘贴到下面。 感谢您的帮助,提前谢谢

package  {

import flash.display.MovieClip;
import CollisionObject;
import flash.events.Event;
import flash.events.TimerEvent; 
import flash.utils.Timer;

public class Player extends CollisionObject {
    private var xMovement:Number;
    public var isAttacking:Boolean;
    private var attackTimer:Timer = new Timer (500, 1);

    public function Player() {
        // constructor code
        trace("I am the player");
        xMovement = 0;
        isAttacking:false;

        addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    } // end constructor

    private function enterFrameHandler(event:Event):void{
        this.x += xMovement;
    } //end function

    public function attack() {
        isAttacking = true;
        this.gotoAndStop("attack");
        attackTimer.addEventListener(TimerEvent.TIMER_COMPLETE, doneAttacking);
        attackTimer.start();
    }

    public function startJumping(){
        if (isJumping == false) {
            isJumping == true;
            this.gotoAndStop("jump");
            downwardVelocity = -20; 
        }
    }

    public function doneAttacking  (event:TimerEvent):void{
        isAttacking = false;
        this.gotoAndStop("stop");
    }

    public function moveLeft() : void{
        xMovement =-7;
        this.scaleX = -1;
        this.gotoAndStop("run");
        isRunning = true;
    } //end function

    public function moveRight() : void{
        xMovement =7;
        this.scaleX = 1;
        this.gotoAndStop("run");
        isRunning = true;
    } //end function

    public function standStill() : void{
        xMovement = 0;          
        isRunning = false;
    } //end function

    override public function positionOnLanding(){
        if(isRunning == true){
            this.gotoAndStop("run");
        }else{
            this.gotoAndStop("stop");
        } //end else
    } //end function
} // end class

你的玩家在无休止地跳跃,因为你从未将iSJumping设置为真。应该是

isJumping = true;
而不是

isJumping == true;
攻击可能不起作用,因为您有自己的攻击帧,并且该帧可能由running或PositionLanding重置


请将您的attackTimer事件监听器移动到构造函数中,现在每次攻击时都会创建一个新的事件监听器,这会导致内存泄漏,并且没有理由这样做。

您的播放器会无休止地跳转,因为您从未将iSJumping设置为true。应该是

isJumping = true;
而不是

isJumping == true;
攻击可能不起作用,因为您有自己的攻击帧,并且该帧可能由running或PositionLanding重置


请将您的attackTimer事件监听器移动到构造函数中,现在每次攻击时都会创建一个新的事件监听器,这会导致内存泄漏,因此没有理由这样做。

您的代码不完整,您在哪里使用
downwardVelocity
?你在哪里调用
startJumping()
attack()
?。你的代码不完整,你在哪里使用
downwardVelocity
?你在哪里调用
startJumping()
attack()
;是跳跃=真;而且玩家不会跳。尽管如此,它仍能播放音效。根据前面的注释,代码不完整。我真的不知道,因为这是一个老项目,我从来没有与AS3在永远。我真的不知道从哪里开始lol。这就像从阁楼上拿出一个旧的坏玩具并试图修复它,但不知道你一开始对它做了什么lol。我改变了isJumping==真;是跳跃=真;而且玩家不会跳。尽管如此,它仍能播放音效。根据前面的注释,代码不完整。我真的不知道,因为这是一个老项目,我从来没有与AS3在永远。我真的不知道从哪里开始lol。这就像从阁楼上拿出一个旧的坏玩具,并试图修复它,但不知道你对它做了什么。