gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > switching backgrounds w/button press

#16182 - darknet - Tue Feb 10, 2004 8:15 am

Hey everyone,

I want to display a bitmap in mode 3 (for its high quality) and then go to another bitmap when the start button is pressed. Basically, I want what would become a splash screen that leads to a menu screen.

Here's what i have so far and all it does is display the first image (because i'm using the same buffer? how'd i clear it? should i use a different mode??):


int main()
{
SetMode(MODE_3 | BG2_ENABLE);

while(1) {

if( ((*BUTTONS) & START_BUTTON)) {

for(int y = 0; y<160; y++)
for(int x = 0; x< 240; x++)
DrawPixel3(x,y, intro_Bitmap[y * 240 + x]);
}

else{
for(int z = 0; z<160; z++)
for(int w = 0; w<240; w++)
DrawPixel3(w,z, blueback2_Bitmap[z*240 + w]);
}

}
return 0;
}


and i obviously have a drawpixel function and the right defines for the buttons. I want to transition between the two when start is pressed.

Thanks for any help and sorry for such a long post,
-Mike

#16186 - FluBBa - Tue Feb 10, 2004 10:28 am

It might not be a problem but it only checks the start button exactly when it has drawn the background, depending on how long this takes you have to hold the start button for some time.
The other obvious thing to ask is if you have declared BUTTONS as volatile?
_________________
I probably suck, my not is a programmer.

#16187 - darknet - Tue Feb 10, 2004 11:56 am

First of all thanks for the quick reply,

Secondly, I did declare the buttons volatile. Also, I included the first bitmap drawing method outside of the while loop and all that did was display the second bitmap.

What i am looking for is a basic mechanism for switching between screens via button presses. More specifically, how does the memory get cleared up if i want to have 2 back to back screens in mode 3 (for example)? I assume I have to manage that memory, but how?

Any details on any of that is greatly appreciated.

Thanks,
-Mike

#16211 - AndOrAFK - Tue Feb 10, 2004 5:54 pm

Using what little knowledge I have, I'd suggest using DMA to copy the new screen in when you press start.

If you can get your bitmap down to 255 colors (I'd be happy to give it a try if you can provide me with the source image), I would suggest using mode 0 and simply tiling the bitmap across the screen.

#16232 - dagamer34 - Wed Feb 11, 2004 1:19 am

Right now your code will only display the first bitmap if the start button is pressed. Is that right? Or do you want it to alternate?

If you want it to alternate, its better to use a bool. Do something like this:

Code:

int main ()
{
   // Setup the video mode
   SetMode (MODE3 | BG2_ENABLE);

  bool showFirst = false;
  // Loop
  while (1)
  {
      // If the start button is pressed, flip the state of the bool
      if (KeyDown (KEY_START))
          showFirst != showFirst;

      // Depending on the state of the bool, show a certain pic
      if (showFirst)
      {
           // Draw the first pic here....
      }
      else
      {
          // Draw the second pic here...
      }
      return 0;
}


If you need any more help, just PM me and I'll see what i can do.
_________________
Little kids and Playstation 2's don't mix. :(