#11848 - goro - Tue Oct 21, 2003 4:45 pm
hi,
my bg1 seems to scroll perfectly, but bg2 wont budge an inch (or a pixel in this case!) and if I swap the bg numbers (in the struct-fill in main) bg2 scrolls but not bg1. There's obviously a problem with updating multiple backgrounds but I can't find it!!
here's some of my code...pleaase help!!
Last edited by goro on Wed Oct 22, 2003 1:28 pm; edited 1 time in total
my bg1 seems to scroll perfectly, but bg2 wont budge an inch (or a pixel in this case!) and if I swap the bg numbers (in the struct-fill in main) bg2 scrolls but not bg1. There's obviously a problem with updating multiple backgrounds but I can't find it!!
here's some of my code...pleaase help!!
Code: |
Bg bg1; Bg bg2; void EnableBackground(Bg* bg) { u16 temp; bg->tileData = (u16*)CharBaseBlock(bg->charBaseBlock); bg->mapData = (u16*)ScreenBaseBlock(bg->screenBaseBlock); temp = bg->size | (bg->charBaseBlock<<CHAR_SHIFT) | (bg->screenBaseBlock<<SCREEN_SHIFT) | bg->colorMode | bg->mosaic | bg->wraparound; switch(bg->number) { case 0: { REG_BG0CNT = temp; REG_DISPCNT |= BG0_ENABLE; }break; case 1: { REG_BG1CNT = temp; REG_DISPCNT |= BG1_ENABLE; }break; case 2: { REG_BG2CNT = temp; REG_DISPCNT |= BG2_ENABLE; }break; case 3: { REG_BG3CNT = temp; REG_DISPCNT |= BG3_ENABLE; }break; default:break; } } void UpdateBackground(Bg* bg) { switch(bg->number) { case 0: REG_BG0HOFS = bg->x_scroll; REG_BG0VOFS = bg->y_scroll; break; case 1: REG_BG1HOFS = bg->x_scroll; REG_BG1VOFS = bg->y_scroll; break; case 2: if(!(REG_DISPCNT & MODE_0))//it is a rot background { REG_BG2X = bg->DX; REG_BG2Y = bg->DY; REG_BG2PA = bg->PA; REG_BG2PB = bg->PB; REG_BG2PC = bg->PC; REG_BG2PD = bg->PD; } else //it is a text background { REG_BG2HOFS = bg->x_scroll; REG_BG2VOFS = bg->y_scroll; } break; case 3: if(!(REG_DISPCNT & MODE_0))//it is a rot background { REG_BG3X = bg->DX; REG_BG3Y = bg->DY; REG_BG3PA = bg->PA; REG_BG3PB = bg->PB; REG_BG3PC = bg->PC; REG_BG3PD = bg->PD; } else //it is a text background { REG_BG3HOFS = bg->x_scroll; REG_BG3VOFS = bg->y_scroll; } break; default: break; } } |
Code: |
if(!(*KEYS & KEY_RIGHT))
{ if ( bg1.x_scroll < 1792 ) // stop scrolling at far right. { if (hero_posx < 100) { hero_posx++; // other stuff } else { bg2.x_scroll++; bg1.x_scroll++; ScrollBg(); // other stuff } } else { hero_posx++; // other stuff } } |
Code: |
int main(void)
{ u16 loop; // Bg initialisation SetMode( MODE_0 | BG1_ENABLE | BG2_ENABLE | OBJ_MAP_1D | OBJ_ENABLE); bg1.charBaseBlock = 0; bg1.colorMode = BG_COLOR16; bg1.mosaic = 0; bg1.screenBaseBlock = 28; bg1.size = TEXTBG_SIZE_256x256; bg1.x_scroll = 8; bg1.y_scroll = 80; bg1.number = 1; bg2.charBaseBlock = 16; bg2.colorMode = BG_COLOR16; bg2.mosaic = 0; bg2.screenBaseBlock = 30; bg2.size = TEXTBG_SIZE_256x256; bg2.x_scroll = 8; bg2.y_scroll =80; bg2.number = 2; EnableBackground(&bg1); EnableBackground(&bg2); |
Code: |
while(1)
{ GetInput(); //check for input WaitForVblank(); //waits for the screen to stop drawing UpdateBackground(&bg2); //make sure registers are updated if anything changes e.g. scrolling UpdateBackground(&bg1); CopyOAM();// Update sprite stuff } |
Last edited by goro on Wed Oct 22, 2003 1:28 pm; edited 1 time in total