1
votes
    private function scrollStage():void 
    {
        if (lastPosX != lastPosX)
        {
            canScrollStage = false;
        }
        else
        if (lastPosX == lastPosX)
        {
            canScrollStage = true;
        }

        if (canScrollStage)
        {
            if (rightKey)
            {
                //move background left
                //something.x +=(stage.stageWidth * 0.5) - character.x * 2;
            }
            else
            if (leftKey)
            {
                //move backgrounf Roight 
            }

            for (var b:int = 0; b  < childrenOnStage; b++)
            {   
                if (getChildAt(b).name == "enemy")
                {
                    getChildAt(b).x +=(stage.stageWidth * 0.5) - character.x
                }

            }
            ground.x += (stage.stageWidth * 0.5) - character.x
        }
        else
        {
            //move the background 
        }
        // do this last, everything moves around object 
        character.x = stage.stageWidth * 0.5;
        lastPosX = character.x;
    }

Someone told me to move the objects around the player and then update the players x position.

This is what I've done by looking at a tutorial ("Cartoon Smart");

In my player class I have a reset function.

    private var xSpeed:int;
    private var resetPos:Point;



    public function player() 
    {

        addEventListener(Event.ADDED_TO_STAGE, onAdd)

    }

    private function onAdd(e: Event): void 
    {
        xSpeed = 3;
        resetPos = new Point(x, y);
    }

    public function reset():void
    {
        x = resetPos.x;
        y = resetPos.y;
        //trace(resetPos);
        //trace(resetPos + "player");
    }   

When the player falls to death this function is called

    private function playerFalls():void 
    {
        if (character.y > stage.stageHeight)
        {
            //take life away and go back to check point or back to reset 
            character.x = stage.stageWidth * 0.5;
            character.y = 20;
            //goblin1.reset();
            //goblin2.reset();
            //goblin3.reset();


            //stage.x = stage.stageWidth * 0.5;
            //canScrollStage = false;
        }
    }

if I use

            character.x = stage.stageWidth * 0.5;

Then my character ends up in the middle, but it will end up in the middle since the scroll function dictates the player to be in the center always.

            character.x = (stage.stageWidth * 0.5) - 400;// moves him back

but if character falls off left of the screen then he is moved back. Any one have a solution for this please?

My question is, I want to reset the player's x position to 300 and y position to 10;

But I can't do this because the stage shifts and the co ordinate system changes.

In order for the player to go back to the original coordinate of the stage, the stage must scroll.

That's my idea, or perhaps the ground and enemies must do the opposite?

2
If you could explain your question a little more I'd be glad to point you in the right direction. I've been creating a platformer game so I'd definitely have the experience to help you out. What exactly do you need help with?DrakeTruber
@DrakeSwartzy thank you! I'm at work now, but ill reply later like 2 hours timeMoynul
@DrakeSwartzy Basically, character.x is always = to stage.stageWith/2Moynul
computing.northampton.ac.uk/~13422770/gameGroup/kdDr.swf This is your code :) when the player falls, I Can reset players x positionMoynul
computing.northampton.ac.uk/~13422770/gameGroup/KD.swf this, code is the the one I'm currently using, I can't reset sir Timmy cause he's always in the middleMoynul

2 Answers

1
votes

I sincerely apologize for the late answer. Okay, so your saying that when the character falls you don't want the screen to scroll all the way back to the character's start position. What you need to do is find the start positions of your character and ground (as well as any other layers such as backgrounds etc). Then wherever your fall function comes into place simply set the character and background positions to their starting coordinates.

function fall(){
    char.x=charStartX;
    char.y=charStartY;
    ground.x=groundStartX;
    ground.y=groundStartY;
    //etc
}
0
votes

For example, let's say you have a check point. If player hits check point charResetPoint = 100. If player falls then set it's x pos to charResetPoint

But I can't move the players x position because it will always be stage.stageWidth/2 due to my code.

So in theory it will be difficult to make a resetPoint, because when I add goblin 1.x , it's x pos is 900, if I scroll right goblon1 x pos will change. Everythings x pos changes and so does the stages.

I can't get a grasp on the concept, sortlry