GP32 No trail?...


Kooli

Still Fresh
Joined
Aug 16, 2003
Messages
13
Location
UK
Website
Visit site
I am trying to draw a sprite to screen and the player can move it around but I get a trail behind the sprite as I am using GpRectFill() . How can I stop this? I tried to use GpRectFill() in the opposite colour behind the sprite but it doesn't work.. Here is the code...

Code:
/*Attempt to draw a sprite and move it around the screen*/


#include "gpstdlib.h"
#include "gpstdio.h"
#include "gpgraphic.h"
#include "gpfont.h"

#define SPRITESIZE 10

void GpMain(void *arg);
void Control_Sprite(void);
void Setup(void);
void Get_Direction(void);
void Side_Check(void);

GPDRAWSURFACE gpDraw[2];  	

/*globals*/
int px,py,keypress,nflip;      /*player x and y coord*/
	
/**************************************************************/

void GpMain(void *arg)
{
Setup();
Control_Sprite();
}

/****************************************************************/

void Setup(void)
{

nflip=1;      	/*set page flipper to page 1 start*/

GpLcdSurfaceGet(&gpDraw[0],0);      /*LCD setup*/
GpLcdSurfaceGet(&gpDraw[1],1);

/*both surfaces to black*/	
GpRectFill(NULL,&gpDraw[1],0,0,gpDraw[1].buf_w,gpDraw[1].buf_h,0x00);
GpRectFill(NULL,&gpDraw[0],0,0,gpDraw[0].buf_w,gpDraw[0].buf_h,0x00);

GpSurfaceSet(&gpDraw[0]);      /*set surface*/

px=py=32;      /*set up starting sprite coords*/

}

/*************************************************************/

void Control_Sprite(void)
{

while(1)
	{
	Get_Direction();	
	Side_Check();	

        /*redraw sprite*/
	GpRectFill(NULL,&gpDraw[nflip],px,py,SPRITESIZE,SPRITESIZE,0xff);  

	GpSurfaceFlip(&gpDraw[nflip++]);    /*flip surface*/
	nflip &= 0x01;        /*change page*/
	}

}

/*************************************************************/
void Get_Direction(void)
{
/*check for keypresses*/

keypress=GpKeyGet();

if(keypress & GPC_VK_LEFT) px--;      
if(keypress & GPC_VK_RIGHT) px++;      
if(keypress & GPC_VK_UP) py--;    	
if(keypress & GPC_VK_DOWN) py++;	
}

/*************************************************************/
void Side_Check(void)        
/*stops player leaving area*/
{
if(px > 160) px=160;  	
if(px < 0) px=0;
if(py > 240) py=240;
if(py < 0) py=0;
}

/********************************************************************************************************/

Thanks in advance

Kooli
 
Back
Top