• Advertisement
Sign in to follow this  

Allegro and Scrolling

This topic is 3141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
'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
Sign in to follow this  

  • Advertisement