Movieclip se mueve junto con el reproductor

My problem is _saw in the flash I'm doing is just moving together with _player unlike _boundary(floor) is just static in the stage

public class PiggyRun extends MovieClip
{


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

my player in the script

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

I declared saw just as the same with boundary

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
        {

I increased x because it's a running game

        _vy+=2;
        _vx+=.5;

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




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

The controls when pressed down

        private function kDHandler(e:KeyboardEvent):void
        {

            switch(e.keyCode)
            {

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

                }
                break;


                default:



            }
        }

I deleted contents of this function

        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;

                        }
                }
            }
        }

I put this function where in if the player hits the sawblade it will respawn back to the location of _rp but as I sad the 2 movieclips wont meet because they move simultaneously even if I forcely put the _saw together with it the function doesn't work

        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;
        }





}

preguntado el 28 de agosto de 12 a las 11:08

Check if you addChild() your _saw object to the _player object. It seems that _saw.parent equals to _player, this makes it move with the player. -

It's a bit hard to read your code like this. Try to clearly ask your question at the top. And then have one solid block of code (with additional comments instead of linebreaks). And like @Vesper I'm also interested in where you instantiate Player y Saw and how you add them to the stage. -

I dont have any addChild, its a very basic flash game, I added saw and player by just drawing them into stage and making them symbols -

Is it possible for you to upload the source file somewhere? I think it'll make a bit more sense for us. -

here you go, it's the .fla and .as file of what I am creating mediafire.com/?f98tava91i8cw5b -

1 Respuestas

I had a look at your fla and you didn't anything weird with the positioning of your MovieClips. The problem lies in your stageFocus function. You're constantly positioning the position of your saw at x=5 and your player at the center of your stage. Only the _boundary is moved. So you should move your _saw like you're moving _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;
}

And on a more general note, I think you're in a bit over your head here. Try narrowing down your game concept or maybe even usar un marco para empezar.

Respondido 29 ago 12, 16:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.