Thread: Allegro Vertical Scrolling

  1. #1
    Registered User godly 20's Avatar
    Join Date
    Jan 2011

    Arrow Allegro Vertical Scrolling

    I'm currently coding a very basic space shooter with the Allegro Library and Dev-C++. However I can't seem to figure out how to make the background scroll on the y axis and this thing has been driving me crazy for the past 2 weeks. Can anyone help me?
    PS: The background image to scrollon y axis is 800x640.
    "A Computer in every desk and in every home, running Microsoft software."

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Use tiles. Scroll the tiles up/down. For tiles you want to draw the portion of the larger map that is on the screen. There are several different algorithms that will do this.

  3. #3
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    United Kingdom
    I did exactly the same thing a while ago. To get the background to scroll you need a bit of maths. The way I did it was to imagine the screen at the bottom of the picture and then increase the drawing coordinates each time. The tricky bit is when you get to the top of the picture and you need to draw the bottom half of the picture on the bottom half of the screen and the bottom half of the picture on the top half on the screen. To do that I used an index and then just reset it back to zero when the screen coordinates crossed the bottom of the picture (needs a bit of imagination to truely understand what I mean). I wrote this code a while ago, but it might help you/give you some ideas how to do it.

    Again, exactly how you do it is up to you. I hope that you take the code posted below and learn from it rather than blindly using it. Also remember, the way I did it may not be the most efficient way this effect can be done.

                                   /* Add Background to the screen buffer - Code more complex because of scrolling */
                                   cindex.background_index0 = static_cast<int>( (cgraphics.GetCurrentBackground()->h - SCREEN_DIMY)/SCROLL_RATE);
                                   if( cindex.background_index <= cindex.background_index0 )
                                       /* Draw Image as normal */
                                       blit(cgraphics.GetCurrentBackground(), cgraphics.GetScreenBuffer(), 0,
                                                      static_cast<int>( cgraphics.GetCurrentBackground()->h - SCREEN_DIMY - (SCROLL_RATE*cindex.background_index) ),
                                                      0,0,SCREEN_DIMX, SCREEN_DIMY);
                                   if( cindex.background_index > cindex.background_index0 )
                                       /* Draw bottom 1/2 of image on top 1/2 of screen */
                                       blit(cgraphics.GetCurrentBackground(), cgraphics.GetScreenBuffer(), 0,
                                                     static_cast<int>(cgraphics.GetCurrentBackground()->h - (SCROLL_RATE*(cindex.background_index - cindex.background_index0))),0,0,
                                                     cgraphics.GetCurrentBackground()->w, static_cast<int>((cindex.background_index - cindex.background_index0)*SCROLL_RATE));
                                       /* Draw top 1/2 of image on bottom 1/2 of screen */
                                       blit(cgraphics.GetCurrentBackground(), cgraphics.GetScreenBuffer(), 0, 0,0, static_cast<int>((cindex.background_index - cindex.background_index0)*SCROLL_RATE),
                                                     cgraphics.GetCurrentBackground()->w, static_cast<int>(SCREEN_DIMY - ((cindex.background_index - cindex.background_index0)*SCROLL_RATE)));
                                       if( SCROLL_RATE*(cindex.background_index - cindex.background_index0) >= SCREEN_DIMY )
                                           /* Reset background_index */
                                           cindex.background_index = 0;
    And then at the end of the screen rendering section you need something like:
                                   /* Update the graphical indicies */

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Got another problem with my Allegro scrolling shooter
    By Swarvy in forum Game Programming
    Replies: 2
    Last Post: 05-14-2009, 04:59 PM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  3. Vertical Scrolling Bitmap in SDL
    By Blizzarddog in forum Game Programming
    Replies: 11
    Last Post: 09-19-2004, 08:14 PM
  4. double buffering for allegro
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 09-12-2002, 02:45 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM

Tags for this Thread