Sign in to follow this  
nGamer

Allegro and Scrolling

Recommended Posts

How exactly would one go about implementing parallax scrolling in Allegro? I have created the layers, marked part of the bitmap with magenta that I want to be masked through, and blitted to the screen - in that order; Nothing works; or more than likely, I am doing something wrong. I can figure the Allegro code out myself - I just need an algorithm.

Share this post


Link to post
Share on other sites
'Nothing works' is pretty vague, but parallax scrolling works by adjusting the speed at which objects seem to move, based on their perceived distance from the screen. I assume that you've already got a 'camera' system worked out if you're expecting to see any kind of a parallax effect, so all you need to do for parallax layers is to offset them by some fraction of the camera movement.

Assuming that layer 1 is the foremost layer, with higher numbered layers extending outward:

int x = sprite.x + (cam.x / sprite.layer),
y = sprite.y + (cam.y / sprite.layer);

draw_sprite(buffer, sprite.currentFrame, x, y);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this