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 > screen redraw is slow, any suggestions please?

#47056 - solarwind__ - Mon Jul 04, 2005 5:28 pm

i have created a program which draws a little blue rectange (10x20 px) in the topleft corner of the gba emulator window. I have used user input (currently only two keys, up and down) to move the little blue rectangle up and down on the screen. The program works but to animate the little blue rectangle, i had to repaint the screen black to prevent the blue rectangle from drawing like a pencil =|. If you understand what I mean. Anyway, the screen repainting is very slow and every time i press the down or up key. the block moves but is very slow due to the screen repainting.

If anyone has any suggestions on how to improve speed or even accomplish the same task which is to (create a little blue rectangle and move up or down the screen when the user press the up or down key) using a different method, i would greatly appreciate it.

Here is my code
Code:

//GBA resolution is 240 x 160

#include "keypad.h"

#define RGB16(r,g,b)  ((r)+(g<<5)+(b<<10))

int main()
{
   char x;
   char y;
   char a; // something like char x
   char b; // something like char y
   char v = 0; //variable that keeps track of the little blue square on the vertical line
   char h = 0; //variable that keeps track of the little blue square on the horizontal line
   
   char k = 5;
   char l = 15;
   unsigned short* Screen = (unsigned short*)0x6000000;
   *(unsigned long*)0x4000000 = 0x403; // mode3, bg2 on

   for (x = 0; x < 240; x++) //starts off with a black screen
      {
         for (y = 0; y < 160; y++)
            {
               Screen[x+y*240] = RGB16(0,0,0);

            }
         
      }




   
   while(1)
   {



         if(!((*KEYS) & KEY_DOWN))
         {


               for (x = 0; x < 240; x++)
               {
                  for (y = 0; y < 160; y++)
                  {
                  Screen[x+y*240] = RGB16(0,0,0);

                  }
         
               }


            k = k + 15;
            l = l + 15;
         

                        for (a = 0; a < 20; a++)
            {   
            
               
               for (b = k; b < l; b++)
               {
               Screen[a+b*240] = RGB16(0,0,30);
            
               
               }
         
            }   

            
         } 

// ==============================================================================


         if(!((*KEYS) & KEY_UP))
         {


               for (x = 0; x < 240; x++)
               {
                  for (y = 0; y < 160; y++)
                  {
                  Screen[x+y*240] = RGB16(0,0,0);

                  }
         
               }


            k = k - 15;
            l = l - 15;
         

                        for (a = 0; a < 20; a++)
            {   
            
               
               for (b = k; b < l; b++)
               {
               Screen[a+b*240] = RGB16(0,0,30);
            
               
               }
         
            }   
         }


            
            

   }


}




I would greatly appreciate it if anyone could supply the code to accomplish the same task even with a completly different method but any suggestions are a big help.

THANKS in advace
_________________
#solarwind

#47057 - poslundc - Mon Jul 04, 2005 5:45 pm

solarwind__ wrote:
If anyone has any suggestions on how to improve speed or even accomplish the same task which is to (create a little blue rectangle and move up or down the screen when the user press the up or down key) using a different method


Sure, use a sprite. That's what they're there for, and you won't have to redraw anything.

Dan.

#47069 - Quirky - Mon Jul 04, 2005 7:24 pm

After that, try it with a bg layer, a tile and the scroll registers. You'll then have a good basic knowledge of the GBA graphics hardware.

#47073 - solarwind__ - Mon Jul 04, 2005 8:22 pm

thanks a lot but what is a sprite? and where can i learn more about them?
_________________
#solarwind

#47074 - solarwind__ - Mon Jul 04, 2005 8:24 pm

i have heard about sprites but had trouble learning about them, if anyone of you can post some links or tell me where i can go to learn more about them, it would be great.

thanks a lot in advance...
_________________
#solarwind

#47090 - poslundc - Tue Jul 05, 2005 1:52 am

http://thepernproject.com/tutorials/GBA/day_3.html

Dan.