Movieclip与玩家一起移动

时间:2012-08-28 10:35:42

标签: actionscript-3 flash symbols

我的问题是_saw在闪光灯中我正在做的只是与_player一起移动不像_boundary(floor)在舞台上只是静态的

public class PiggyRun extends MovieClip
{


private var _vy:Number;
private var _vx:Number;

脚本中的播放器

public var _player:player;
public var _boundary:Boundary;
public var _rp:RG;

我声明与边界

一样
public var _saw:saw;
public var _jump:Boolean=true;



    public function PiggyRun():void
    {
    _rp.visible=false;
    _vx=0;
    _vy=0;
    _player.gotoAndStop('walking');
    stage.focus= stage;
    this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, kDHandler);
    stage.addEventListener(KeyboardEvent.KEY_UP, kUHandler);


    }

        private function enterFrameHandler(e:Event):void
        {

我增加了x,因为它是一个正在运行的游戏

        _vy+=2;
        _vx+=.5;

        if(_vx>10)
        {
            _vx=10
        }
        _player.x+=_vx;
        _player.y+=_vy;




        borders();
        stageFocus();
        sawblade();
        }

按下时的控件

        private function kDHandler(e:KeyboardEvent):void
        {

            switch(e.keyCode)
            {

                case 38:
                if(_jump){
                _jump=false;    
                _vy=-20;

                }
                break;


                default:



            }
        }

我删除了此功能的内容

        private function kUHandler(e:KeyboardEvent):void
        {
            switch(e.keyCode)
            {


            }
        }

        private function borders():void
        {
            if(_vy > 0)
            {
                if (_player.y>stage.stageHeight)
                {
                    _player.x=_rp.x;
                    _player.y=_rp.y;
                    _boundary.x=0;
                    _boundary.y=0;
                    _saw.x=0;
                    _saw.y=0;
                    _vy=0;
                    _vx=0;

                }else{
                    var border:Boolean=false;

                    if(_boundary.hitTestPoint(_player.x,_player.y,true))
                    {
                    border=true;

                    }
                        if (border)
                        {
                            while(border)
                            {

                            _player.y-=0.05;

                            _jump=true;
                            border=false;
                                if(_boundary.hitTestPoint(_player.x,_player.y,true))
                                {
                                border=true;

                                }
                            }
                            _vy=0;

                        }
                }
            }
        }

我把这个功能放在哪里如果玩家击中锯片,它会重新生成回到_rp的位置但是我很难过,因为他们同时移动了2个动画片段 即使我强行将_saw与它一起放置,该功能也不起作用

        private function sawblade():void
        {
            if(_vy > 0)
            {
                if (_player.y>stage.stageHeight)
                {
                    _player.x=_rp.x;
                    _player.y=_rp.y;
                    _boundary.x=0;
                    _boundary.y=0;
                    _saw.x=0;
                    _saw.y=0;
                    _vy=0;
                    _vx=0;

                }else{
                    var sawn:Boolean=false;

                    if(_saw.hitTestPoint(_player.x,_player.y,true))
                    {
                    sawn=true;

                    }
                        if (sawn)
                        {
                            while(sawn)
                            {

                            _player.x=_rp.x;
                            _player.y=_rp.y;
                            _boundary.x=0;
                            _boundary.y=0;
                            _saw.x=0;
                            _saw.y=0;
                            _vy=0;
                            _vx=0;
                            _jump=true;
                            sawn=false;
                               if(_saw.hitTestPoint(_player.x,_player.y,true))
                            {
                                sawn=true;

                                }
                            }
                            _vy=0;

                        }
                }
            }
        }
        private function stageFocus():void
        {
            _boundary.x+=(stage.stageWidth * 0.5)-_player.x;
            _player.x=stage.stageWidth*0.5;
            _saw.x=5;
        }





}

1 个答案:

答案 0 :(得分:0)

我看了你的fla,你对MovieClip的定位并没有什么奇怪的。问题在于您的stageFocus功能。你经常将你的锯的位置定位在x = 5,你的玩家位于你舞台的中心。仅移动_boundary。因此,您应移动_saw,就像移动_boundary一样。

private function stageFocus():void
{
    var playerOffset:int = (stage.stageWidth * 0.5)-_player.x;

    _boundary.x+= playerOffset;
    _player.x=stage.stageWidth*0.5;
    _saw.x+=playerOffset;
}

更一般地说,我认为你在这里有点过头了。尝试缩小您的游戏概念,甚至可能use a framework让您开始。