Thread: very simple question

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    Unhappy very simple question

    Hi,guys

    In the game,how could I make the background to keep moving with only one ground bitmap?
    Is there any trick for this?

    ThanX!!
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    If you mean moving like side-scrolling then you can try this:

    Say for instance your game screen is 300 pixels wide and your
    background bitmap 300 pixels wide too. Define a variable (int i for
    our purposes) to hold the start of your bitmap (at first this would
    be 0). When needed (say the user pushes the right arrow key to
    make your hero walk), you incriment the bitmap start int. In your
    blit routine you would test to see if(i==0). If so, then blit your
    bitmap starting a 0. If not, run a blit 2 instances of your bitmap.
    The first will have a Source X of whatever i equals, will have a
    width of (300-i) and will have a Destination X of 0. The second will
    have a Source X of 0, a width of (300-i) and a Destination X of i.

    Here's an example (pseudo) of this if the hero walks 10 pixels to
    the right:

    Code:
    //look, Ma! Code tags! 
    
    if(i==0)
    {
       blit grass.bmp starting at destinatin 0 with source width of 300 
    and source starting at 0
    }
    else
    {
      //1st part
      blit grass.bmp starting at destination 0 with source width of 290 
    and source starting at 10
    
      //2nd part
      blit grass.bmp starting at destination 290 with source width of 
    10 and source starting at 0
    }
    If this isn't what you're looking for let me know and hopefully I
    can explain another method.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    /////------------------------------------------------------------------------------

    If not, run a blit 2 instances of your bitmap.
    The first will have a Source X of whatever i equals, will have a
    width of (300-i) and will have a Destination X of 0. The second will
    have a Source X of 0, a width of (300-i) and a Destination X of i.

    ////-------------------------------------------------------------------------------


    Thank you very much for the help, but about the blit 2, you mean
    first have a source X of whatever i equals, and the width of (300-i)
    and blit to destination X of 0. The second will have a source of 0, a width of i and destination start of (300-i)

    and test
    (if i ==300)
    i= 0;
    blit 1;

    am I right?
    Don't laugh at me,I am just a SuperNewbie.

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    and test
    (if i ==300)
    i= 0;
    blit 1;
    Yes. Sorry I forgot to mention checking for i==300 to reset itself,
    but that's right.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM