PDA

View Full Version : Help with smooth Horizontal scrolling



robotz
January 19th, 2008, 12:09 PM
Hi all,

I was just wondering what your tips would be on achieving smooth horizontal scrolling in AS3? (browser based game). I've been testing two core methods: using the scroll() method of bitmapData, and using just a plain copyPixels() loop (from the hidden map data to the "screen buffer").

Both techniques work, but neither are what I'd class as "smooth" when running at speed. My game size is 576 x 416, I'm running at 30fps and there is nothing on-screen except one player (a sprite) and a background. You can see the game in progress here: http://www.fatal-design.com/gofish/ (please note this is only 4 hours work so far, don't expect Crysis ok).

I have a bitmapData object which is the game size for the "screen", and I have another bitmapData object which contains the map (the cavern walls seen in the game). The map is the same width as the screen + an extra 128 pixels. I scroll the map to the left, when I have scrolled 32 pixels I draw the next segment of the map onto the far right of it. In short the map bitmap always stays the same width and refreshes itself every 32 pixels.

As I said, this works fine, it just isn't very smooth! Ideas very welcome, thank you!

parkerdc
January 19th, 2008, 01:02 PM
Roboz

There is a flash game site that has an article on smooth scrolling with source.

http://www.gotoandplay.it/_articles/2004/10/scroller.php

robotz
January 19th, 2008, 03:13 PM
Sorry but while nice that source is too old to be much use in AS3 (and also wasn't particularly smooth either, but I suspect more a symptom of being nearly 4 years old than any lack of coding skill)

ArmoredSandwich
January 19th, 2008, 07:37 PM
Not really on the topic of scrolling..

Do you know that game with the helicopter flying trough a tunnel, allmost exactly the same as your game here? I'm just informing you so you do not hope you think your game is original. But I can imagine you are rebuilding that game xD.

robotz
January 19th, 2008, 07:57 PM
lol, I wouldn't for a second claim the idea was original, of course it was copied! It has been around for decades now, and was a good place to start learning horizontal scrolling in AS3.

hatu
January 19th, 2008, 09:14 PM
Well it's not really lagging or anything for me. The only way I could think of making it smoother is raising the FPS and having it move only 1 pixel per frame if its moving more than that now

robotz
January 20th, 2008, 06:54 AM
Thanks for the feedback Hatu - it doesn't really "lag" for me, it just isn't what I would consider "smooth". At the moment it is moved based on the difference in timers per frame in order to provide a consistent frame rate regardless of PC.

Can you (or anyone reading this) think of any examples of Flash games that you consider to have smooth decent horizontal scrolling? Just so I can see if this is a trait to Flash, or something in my code :)

ArmoredSandwich
January 20th, 2008, 07:57 AM
You must have misunderstood me a bit. I thought you were remaking the game, but just to be sure I thought that I should inform you, just in case.

Anyways, a nice bug for you:
http://www.wonima.demon.nl/other/bugWeird.JPG

And about the scrolling part. I don't know what exactly you had in mind. I mean, you can't go anymore smoother than your scroll speed, right? The only thing that might could work is what hatu said. I personally think that is way to much effort for something hardly noticeable.

robotz
January 20th, 2008, 08:24 AM
Yeah the bug is because of the collision coordinates (top left of the fish rather than center, and the map scrolls another 32px segment after the collision happens).

If you're happy with how smooth it is then that's good enough for me. I am coming at this from a PC game development background so I'm used to linking my scrolling with the GPU and having it frame perfect, so when I see Flash games (especially mine!) that aren't as smooth as butter, I can never tell if it's just the way Flash is, or my code.