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 > newb: backgrounds and sprites on both screens

#149367 - mud2005 - Sat Jan 19, 2008 5:37 am

Hi everyone, this is my first post as I am new to nds development. Ive been messing with libnds and reading everything I can find, but I have a couple questions.
Im writing a simple 2d space game to learn the nds, I want both screens to act as one big screen for both backgrounds and sprites and I want the bg to scroll. I was able to get a scrolling bg working but its 2 256x256 images, one on each screen. and its not perfect since the screen is 192 high instead of 256.
Whats the proper way to do 1 lg screen, should I be using 1 or 2 images for the background?
should I use mode 6 for lg bitmap? will my sprites be able to go from screen1 to screen2 seamlessly? thanks for answering my beginner questions, I did search the forum and couldnt find the answer.

#149394 - tepples - Sat Jan 19, 2008 3:07 pm

Both screens can't read the same VRAM at once. You will have to draw the same scene to both screens separately, with the camera offset down by 192+88=280 pixels on the touch screen.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#149420 - mud2005 - Sat Jan 19, 2008 10:42 pm

Thanks for reply, I managed to get a scrolling background on both screens with 2 images, but to scale to screen height(192) I did this:
Code:
SUB_BG3_YDY = 340;
instead of
Code:
SUB_BG3_YDY = 1 << 8;
not sure why 340 works but it does.
Also I managed to get a sprite to show on both screens, but I want it to go from one to the other, is there a proper way to do this? do I need to make one sprite hidden when it shouldnt be shown? something like, if (sprite on main screen posY > SCREEN_HEIGHT) hide main sprite and show sub sprite?

#149422 - tepples - Sat Jan 19, 2008 10:53 pm

mud2005 wrote:
Thanks for reply, I managed to get a scrolling background on both screens with 2 images, but to scale to screen height(192) I did this:
Code:
SUB_BG3_YDY = 340;
instead of
Code:
SUB_BG3_YDY = 1 << 8;
not sure why 340 works but it does.

I'll tell you why it works. To shrink 256x256 down to 256x192, every 4 lines of the image need to scale to 3 screen lines, and 4/3 = 1.333. The scale factor your program uses is 340/256 = 1.328, which is close enough.

Quote:
Also I managed to get a sprite to show on both screens, but I want it to go from one to the other, is there a proper way to do this? do I need to make one sprite hidden when it shouldnt be shown? something like, if (sprite on main screen posY > SCREEN_HEIGHT) hide main sprite and show sub sprite?

Pretty much. To hide a sprite on the GBA or DS, mark it as unused by writing a special value 512 to attribute 0 of the OAM entry. This value is called ATTR0_DISABLED in libnds and libgba. (Technically, this value turns on the double-size bounding box for rot/scale without turning on rot/scale itself, and the 2D core recognizes this as a signal to just ignore the sprite.)
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#149424 - mud2005 - Sat Jan 19, 2008 10:57 pm

Excellent, Thanks :)