# [GRRLIB (Wii)] Problem scrolling a background

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

## 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 on other sites
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 on other sites
Quote:
 Original post by Sol BlastI'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!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634088
• Total Posts
3015451
×