How do you get the screen to scroll?

7 posts

Flag Post

i’ve tried looking through a bunch of tutorials to figure out how to get the screen to scroll in my game, but the few tutorials that actually touched the subject simply said to move every object except the main character by the main characters velocity. that seems a bit inefficient, isn’t there some way to simply change the coordinates of the center of the screen? if anyone could tell me if it’s possible and how to do it, that’d be great, TIA

 
Flag Post

If you put everything in one big MovieClip, you could move that around. You’d need to treat positions inside that as the absolute coordinates – which might lead to some tooing and froing with converting mouse coordinates. But I imagine that is how most people do it.

Alternatively, if you’ve got an unanimated, bitmapped background graphics you could blow that into a screen-size bitmap, which you can then scroll.

 
Flag Post

so there’s no way to simply move the screen or frame of reference… damn! ok, thanks for the response Lysis :)

 
Flag Post

Um, I don’t think that is the right response to what I said. You’ve probably misunderstood.

this.createEmptyMovieClip("z", 0);//Create a container movieclip

//Put your stuff inside it:
z.attachMovie("asset1","obj1",0,{_x:100,_y:100});//this is an object
z.attachMovie("asset2","obj2",1,{_x:200,_y:50});
//....more objects...

function onEnterFrame(){//frame loop

//move the screen around by moving the outer movieclip
z._x+=1;//move world right 1 pixel per frame

//move your objects around inside the movieclip
z.obj1._y++;//first object moves down in world 1 pixel per frame
z.obj2._rotation+=10;//second object rotates
}//end of frame loop

I think it does what you’re asking for.

 
Flag Post

ooooooohh… hahaha, woops! i don’t 100% understand what you just wrote, but i just finished coding something similar i think, though it may be less efficient- i assigned every object a pair of variables for their “real” x/y coordinates and then created an object which moves every object to be in its relative location to the player (who is, by default, at the center of the screen, though the player can press buttons to “move the camera” in a sense). i’ve never seen anything refering to container movieclips before (i’m pretty new to flash still), sounds handy, i should look it up

 
Flag Post

Technically, you could use root.x and root.y

 
Flag Post

Even easier still! Why didn’t I think of that?
Some people frown on using root, since it may cause embedding
trouble. As I understand it you ought refer to it relatively instead
(use this.
x or whatever).

I suppose you lose a little control, in that you can’t then easily have interface elements which don’t move, or temporarily swap it out for another screen. But that may not be a problem, depending on your game.