0
votes

Okay so I know how to move the stage within the actual .fla file by modifying this.x and this.y variables in the layer 1 actionscript.

But within the document class- public class Starlight extends MovieClip, it does not seem to work no matter what i try and my research lead me to this use code instead:

for( i = 0; i < stage.numChildren; i ++){
        stage.getChildAt(i).x -= player.speedx * player.bounceSpeed;
    stage.getChildAt(i).y -= player.speedy * player.bounceSpeed;
}

I do realize that its hacky and slower as compared to actually moving the stage itself. And i'm not sure what's going to happen if another object that moves comes into the stage because technically this code is unnaturally altering the x,y of everything in the stage.

Any help appreciated!! Cheers

Edit: Tried this--

    var stage2:Sprite = new Sprite();
        stage2.x = stage.stageWidth / 2;
        stage2.y = stage.stageHeight / 2;
        stage2.width = 4000;
        stage2.height = 4000;
        addChild(stage2);

        for (i = 1; i < 50; i ++)
        {
            var asteroid:Asteroid = new Asteroid();
            asteroid.x = Math.round(Math.random() * stage.stageWidth * 4);
            asteroid.y = Math.round(Math.random() * stage.stageHeight * 4);
            stage2.addChild(asteroid);
            collisionList.addItem(asteroid);
            asteroids.push(asteroid);
        }
1
What sort of result are you getting? An error, or nothing at all, or?..Andrey
the asteroids do not spawn at all and i cant collide into them with Player. If I remove the stage2 from addchild(asteroid) they will spawn.iCeCee

1 Answers

1
votes

Woah, don't move the stage!

Create a MovieClip or a Sprite and stick everything in there, then it's just a case of moving that object.

var stage2:Sprite = new Sprite();

stage2.addChild(something);
stage2.addChild(somethingElse);

stage2.x = 10;
stage2.y = 10;