Jump to content
  • Advertisement
Sign in to follow this  
Puyover

[GRRLIB (Wii)] Problem scrolling a background

This topic is 3579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone! I'm making a game for Wii with the grrlib libary wich work over libogc, but I'm having a problem with a tiled based background; I can't scroll it. This is my code: The map:
const short Back_map[3][4] = {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }
};



The function wich draw the map:
void DrawMap(void) {
	short i, j;
	
    for(j = 0; j < 4; j++) {
     for(i = 0; i < 3; i++) {
		 Back.x = j * Back.w;
		 Back.y = i * Back.h;
		 GRRLIB_DrawTile(Back.x, Back.y, Back.w, Back.h, Back.texture, 0, 1, 1, 255, Back_map[j], 1);
		 Back.y = Back.y + 5; // With this line and below, the map should scroll, but it doesn't move :S
		 if(Back.y == Back.h) Back.y = 0;
     }
    }
}


The function GRRLIB_Drawtile(...) is GRRLIB_DrawTile(xpos,ypos,tilewidth,tileheight,texture,rotation,scaleX,scaleY,alpha,tile,number of tile); The map is drawed correctly but it doesn't move... Some help? Thanks and greetings!!

Share this post


Link to post
Share on other sites
Advertisement
I'm not familiar with that library so I can't be 100% on this, but I think I see your problem.


for(j = 0; j &lt; 4; j++) {
for(i = 0; i &lt; 3; i++) {
Back.x = j * Back.w; //This will always set x to the same position, unless w change. Undoing any changes you made to it elsewhere.
Back.y = i * Back.h; //Likewise for y and h.
GRRLIB_DrawTile(Back.x, Back.y, Back.w, Back.h, Back.texture, 0, 1, 1, 255, Back_map[j], 1);
Back.y = Back.y + 5; //You now increament your position, but it means nothing because you reset it each time before you draw it.
if(Back.y == Back.h) Back.y = 0;
}
}



In short, your modification of x is undone each time you go to draw your background. Therefore you'll never see the change.
My advice would be to draw it against a stored offset value which you then change as nessecary (instead of Back.y).

Share this post


Link to post
Share on other sites
Quote:
Original post by Sol Blast
I'm not familiar with that library so I can't be 100% on this, but I think I see your problem.

*** Source Snippet Removed ***

In short, your modification of x is undone each time you go to draw your background. Therefore you'll never see the change.
My advice would be to draw it against a stored offset value which you then change as nessecary (instead of Back.y).

Thank you!

I've understood your idea and now it works:


void DrawMap(void) {
short i, j;

Back.offset += 2;

for(j = 0; j < 4; j++) {
for(i = 0; i < 4; i++) { // I've added a new row to the matrix...
Back.x = j * Back.w;
Back.y = i * Back.h;
GRRLIB_DrawTile(Back.x, (Back.y + Back.offset) - Back.h, Back.w, Back.h, Back.texture, 0, 1, 1, 255, Back_map[j], 1); // ... because the -Back.h, to avoid a black row in the screen
if(Back.offset == Back.h) Back.offset = 0;
}
}
}





Thank you again!!

Greetings!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!