Smooth Scrolling

Started by
1 comment, last by NickyP101 19 years ago
Hey all, lol jeez i been posting on these forums for a while now, this game is just an amazing learning experience lol ok so as most of you know im making a 2d top down multiplayer (networked) scrolling shooter, so far done everything, just putting in some extra details. Anyway the other day in one of my questions, smooth scrolling was brought up, meaning atm my game the players moves one tile at a time, i really dont want this. Anyone know any tutorials on smooth scrolling? or can anyone give me a general over view of the design and i think i might be able to implement it? Any help would be great :) Thanks in advance, Nick
Advertisement
Smooth scrolling shouldn't by that much trouble if you've already put together most of a game.

The first thing is to store each objects position in floats. This allows you to increment their position by fractions of pixels which is required for smooth scrolling.

The next important thing about smooth scrolling is how far you move each character each frame. Usually you mutliply their speed by the inverse of the framerate. So xmoved = xspeed * (1/FPS). If you think about this means that the lower the framerate the more the object moves each frame. There are complicated methods of getting a value for the FPS whih result in uber-smooth scrolling but I found that simply getting the FPS by getting the inverse of the timetaken to process the last frame is usually adequite. so now xmoved = xspeed * TimeForLastFrame (because 1 / (1 / TimeForLastFrame) == TimeForLastFrame). Now the objects should be moving smoothly over the map.

The last thing is that you are going to have to make sure that you render everything that should be on the screen. So if the screen usually takes 20x20 tiles then you should probably be rendering 22x22, to make sure that you cover all the sides.

Hope that helps
Thx mate :) Ill give that a try!

This topic is closed to new replies.

Advertisement