ActionScript 3无法看到Movieclip

时间:2014-06-02 02:41:56

标签: actionscript-3 movieclip

当我玩我的游戏时,它没有显示我的_Player Movieclip,但它确实与地面相撞,这非常令人困惑。所以我相信movieclip在那里,但没有显示纹理/ Sprite。

我认为问题出在“函数Spawn”(第一函数)中。

 public class PewdyBird extends MovieClip
{

    //Player variables
    public var Up_Speed:int = 25;
    public var speed:Number = 0;
    public var _grav:Number = 0.5;
    public var isJump:Boolean = false;
    public var Score:int = 0;
    public var Player_Live:Boolean = true;
    public var _Player:Player = new Player();
    //Other variables

    //Environment variables
    var Floor:int = 480;
    var Clock:Number = 0;
    var Clock_restart:Number = 0;
    var Clock_ON:Boolean = false;
    var Clock_max:int = 15;
    var Player_Stage:Boolean = true;
    private var _X:int;
    private var _Y:int;
    private var hit_ground:Boolean = false;
    private var width_BG:int = 479;

    //SPAWN
    function Spawn(e:Event){
        _Player.x = 200;
        _Player.y = 200;

        stage.addChild(_Player);
    }

    //Keyboard Input
    private function KeyboardListener(e:KeyboardEvent){
        if(e.keyCode == Keyboard.SPACE){
            Clock = Clock_restart;
            Clock_ON = true;
            isJump = true;

            if(isJump){
                _Player.gotoAndPlay("Fly");
                speed = -Up_Speed;
                isJump = false;
            }
        }
    }

    //Mouse Input & Spawn Listener
    private function MouseListener(m:MouseEvent){
        if(MouseEvent.CLICK){
            Clock = Clock_restart;
            Clock_ON = true;
            isJump = true;

            if(isJump){
                _Player.gotoAndPlay("Fly");
                speed = -Up_Speed;
                isJump = false;
            }   

        }
    }

    //Rotation Fly
    function Rot_Fly(){

        if(Clock < Clock_max){
            _Player.rotation = -15;

        }else if(Clock >= Clock_max){

            if(_Player.rotation < 90){
                _Player.rotation += 10;

            }else if(_Player.rotation >= 90){
                _Player.rotation = 90;

            }

        }   
    }
    //END

    //Update Function
    function enter_frame(e:Event):void{
        Rot_Fly();

        //Clock 
        if(Clock_ON){
            Clock++;
        }else if(Clock > Clock_max){
            Clock = Clock_max;
        }

        //Fall Limits
        if(speed >= 20){
            _Player.y += 20;
            return;
            _Player.gotoAndPlay("Fall");
        }
        //Physics
        speed += _grav*3;
        _Player.y += speed;
    }


    //Hit Ground
    function Hit_Ground(e:Event){

        if(_Player.hitTestObject(Ground1)){
            _grav = 0;
            speed = 0;
            trace("HIT GROUND");
        }else if(_Player.hitTestObject(Ground2)){
            _grav = 0;
            speed = 0;
            trace("HIT GROUND");
        }else if(_Player.hitTestObject(Ground1) == false){
            _grav = 1;
        }else if(_Player.hitTestObject(Ground2) == false){
            _grav = 1;
        }
    }


    //Background Slide (Left)
    private function Background_Move(e:Event):void{
        Background1.x -= 1.5;
        Background2.x -= 1.5;
        Ground1.x -= 4;
        Ground2.x -= 4;

        if(Background1.x < -width_BG){
            Background1.x = width_BG;
        } else if(Background2.x < -width_BG){
            Background2.x = width_BG;
        } else if(Ground1.x < -width_BG){
            Ground1.x = width_BG;
        } else if(Ground2.x < -width_BG){
            Ground2.x = width_BG;
        }
    }


}

eventListeners是flash in self

stage.addEventListener(Event.ENTER_FRAME, enter_frame);
stage.addEventListener(Event.ENTER_FRAME, Hit_Ground);
stage.addEventListener(KeyboardEvent.KEY_UP, KeyboardListener);
stage.addEventListener(MouseEvent.CLICK, MouseListener);
stage.addEventListener(Event.ENTER_FRAME, Background_Move); 
stage.addEventListener(Event.ADDED_TO_STAGE, Spawn);

Player.as

 package
{
    import flash.display.MovieClip;

    public class Player extends MovieClip
    {
        public function Player()
        {
            super();
        }

    }
}

1 个答案:

答案 0 :(得分:0)

检查库中的影片剪辑类(AS3链接)是否与播放器类的名称匹配。此外,如果PewdyBird是您的文档类,则可以在构造函数中移动ADDED_TO_STAGE事件。东西,比如:

public function PedwyBird() {

    if (stage) {
      initStage();
    } else {
      addEventListener(Event.ADDED_TO_STAGE, initStage);
    }

}

然后您可以在initStage函数中调用spawn函数,同时添加所有事件侦听器。您也可以使用一个输入框架功能而不是三个。

private function initStage(e:Event = null){
   Spawn(); //of course, you have to remove the e:Event from Spawn declaration

   stage.addEventListener(Event.ENTER_FRAME, enter_frame);
   stage.addEventListener(Event.ENTER_FRAME, Hit_Ground);
   stage.addEventListener(KeyboardEvent.KEY_UP, KeyboardListener);
   stage.addEventListener(MouseEvent.CLICK, MouseListener);
   stage.addEventListener(Event.ENTER_FRAME, Background_Move); 
}