View Full Version : AS2 scroll
Press_Tilty
July 3rd, 2009, 12:14 AM
I'm making a platformer (PopeMan the FlowerHead - don't ask), but I need to scroll. I saw a sample in a book, but it was AS3 and expensive. Could somebody point me to a good scrolling tutorial (i looked at the platformer tutorial here, but it didn't cover scrolling (or I missed it).
thanks,
Press_Tilty
bluemagica
July 3rd, 2009, 10:28 AM
well just google "as3 scrolling tutorial", and you will find lots of those! but basically, scrolling means, move your level instead of the hero! so say, when you press right arrow, hero moves right.... and lets assume you have a movieclip called "lvl" which contains the background and the entire level (enemies, platforms, whatever)... so you can do something like
//first in the keyDown event, i assume there's a boolean set to check if right is pressed!
//then on enterframe event
if(right==true)
{
hero.x+=4;
if(hero.x>(stage.stageWidth/2)) //if hero has moved more than half of the viewable area
{
lvl.x-=4; //move both the level and hero towards left, creating illusion of scrolling
hero.x-=4;
}
}
That's the general logic, and if i remember correctly, the tutorial here covers it well too! Oh and my code over there is just a sample, it still needs other checks, like distance to end of level....but that you will understand better in the tutorial!
TOdorus
July 3rd, 2009, 12:22 PM
Press_tilty I'm guessing you're new to AS and maybe coding in general, so you might ignore my post, as bluemagica's suggestion is much better suited to "get the hang of it".
scrolling means, move your level instead of the hero!
I'm no fan of that method (it isn't the only one ;)), because it distorts the x and y position, making them totally relative of the player. I rather work with an engine that stores the absolute x and y positions based on a arbritrary point of origin. This way a position like (5,10) will always indicate the same spot no matter if the player moved or not. To display the action on screen, find out where the topleft and bottomright corner of the screen are and display the items that are onscreen.
This absoluteness of positions allows you to seperate your model from your view. You can do calculations without anything bieng displayed onscreen (in another word simulate). This may seem totally useless, but this means that you can choose any way to display your game and don't have to render objects that are offscreen just so you collision detection etc will work.
Press_Tilty
July 3rd, 2009, 03:35 PM
Thanks, that was quick. I'm newish to AS2, Iv'e started alot of games and hit roadblocks like this and drifted away. This on the other hands, is a present, so I will finish. I think i'll try the "illusion method"
bluemagica
July 3rd, 2009, 04:08 PM
Todorus, that kind of scrolling is best done at a later stage with bitmapData based level generations, it's not something a beginner can do yet!
TOdorus
July 3rd, 2009, 06:02 PM
@BlueMagica
That's why I said my post could be ignored if necessary. I just wanted to make the point that it isn't the only method. My first attempt at a game with scrolling actually used this method, ony then with movieclips.
@Press_Tilty
Good luck to you and be sure to start a thread here with a link when it's finished!
flyingmonkey456
July 5th, 2009, 04:53 PM
okay, i'm 2 days late.
the easiest way to do this is an active camera. this way, you can move your hero instead of the ground.
here it is for as2
http://www.oreillynet.com/pub/a/javascript/2004/08/17/flashhacks.html?page=last&x-showcontent=text
and as3
http://bryanheisey.com/blog/?p=1
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.