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.

DS development > Scrolling Backgrounds

#85156 - PacoChan - Sat May 27, 2006 2:57 pm

Hi, sorry for my english, I'm spanish. I'm doing a horizontally-scrolling shooter game, where you fly in the space with a spaceship. I have some 16bit bitmaps that are 512x192 pixels. What I want is that this bitmap scrolls horizontally and been repeated when it reaches to the end of the bitmap. So... now that i'm able to show sprites, I don't know how to do this. I've been looking some examples that come with libnds but trere's no one of what I want to do. Could you explain how to do that, with examples(if it's possible)? Thanks.

#85169 - Linkiboy - Sat May 27, 2006 4:50 pm

The best example for what yer talking about would have to be in PALib. Go download it and look at the examples.

http://www.palib.com/

#85241 - knight0fdragon - Sun May 28, 2006 4:08 am

what you could do is have 2 BGs pointing to the same image

then when u hit the end of BG1, BG2 begins, when u hit the end of BG2, BG1 begins
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#85261 - PacoChan - Sun May 28, 2006 8:43 am

Hi, that is another thing that I don't understand very well. I have two BGs but when I draw something in one of them, it appears on both. What do I have to do to fraw one bitmap in one BG and another bitmap in the other BG?

I have also seen in video.h in libnds that are some defines: BG_MOSAIC_ON, BG_MOSAIC_OFF, MOSAIC_CR, SUB_MOSAIC_CR, BG_MOSAIC_ENABLE. Could these defines do that one background is repeated? I tried some of them but it does nothing.

#85369 - rooter - Mon May 29, 2006 3:32 pm

Look into tile based backgrounds and use a 64x32 tile background and write new tiles into the offscreen area as you are scrolling around.

#85376 - silent_code - Mon May 29, 2006 4:38 pm

i can't give you code, but the possibility for repeating backgrounds is there for sure! (i remember messing around with bgs on gba and i had repeating bgs... maybe some certain bits need to be changed... ? still: no code available! though i wish i had... damn hdd crash *upset*) imo using two bgs for the visible effect of one infinitely scrolling bg is a bit overkill and definitly a waste of hardware resources.

if you have multiple (that means separate) (bitmap) backgrounds you need to write the data into the screen base block memory. then you need to assign a "starting memory block" for each bg. that is typically the first tile (though it is a bmp bg) ;)

example (might not be 100% correct, but it works fine for me - worked that out by trial and error ;p ):

setting up the bgs bmp base:

Code:
BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(4) | BG_PRIORITY(0);

BG3_CR = BG_BMP8_256x256 | BG_PRIORITY(3);


now loading some image data into the background (NOTE: i use 256x192 8bit bmp bgs, but it also workes with 16bit - though you may have to adjust some values):

Code:
for(i = 0; i < 256; i++)
// load the bg p?alette into bg palette memory

BG_PALETTE[i] = ((u16*)bg8_pal_bin)[i];

// load the lower bg (bg3) img data

for(i = 0; i < bg8_img_bin_size / sizeof(uint16); i++)
((uint16*)SCREEN_BASE_BLOCK(0))[i] = ((uint16*)bg8_img_bin)[i];

// reset the upper bg (bg2) img data for some random drawing (NOTE: remember the bus is 16bit, so you always draw 2 pixels at once in this mode! because of that it's 128 * 192, not 256 * 192 - and yes, i could have calculated that value instead of doing the multiplication, lazy me ;p )

for(i = 0; i < 128 * 192; i++)
((uint16*)SCREEN_BASE_BLOCK(32))[i] = 0;


hope that helps with the same stuff on both bgs issue.

feel free to ask for some help, of just send me over some code and i'll try to make it work (as soon as i get some minutes off ;p ).

#85394 - knight0fdragon - Mon May 29, 2006 9:50 pm

how is it hardware overkill, its 2 bgs pointing to the same area in memory with different settings in CX registers

Code:

psuedocode

load the  bitmap and have both bg point to it
BG1_CX = 0
BG2_CX = 256

for x < length
{
BG1_CX--;
if BG1CX == -256
  BG1CX = 256
BG2_CX--;

if BG2CX == -256
  BG2CX = 256
}





if there is some wraparound bit setting then the second BG can just be eliminated[/code]
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#85395 - silent_code - Mon May 29, 2006 9:58 pm

you're right, the term "overkill" was a bit exaggerated. well, i just think one can do so much more with two separate backgrounds than using both of them to simulate one continous bg... ;) especially when there's hardware support for that... (i'm not 100% sure - could someone confirm or deny that?!)

#85439 - SteveH - Tue May 30, 2006 11:10 am

You do relise that the DS screen is 256 pixels across or 32 tiles across, so to do horizontal scrolling you will need a 64x32 tile map, thus 2 map bases are assigned to the bg with that will be seamless, or if it's a bmp image you might be able to get away with a 256x256 image and update x columns (x = speed of scroll) per vblank, but it might be a tad slow to do...

#85447 - PacoChan - Tue May 30, 2006 1:58 pm

Hi, I finally did what knight0fdragon said and it works perfect. I would prefer to use only one background but it doesn't matter. Thanks everyone.

#85448 - silent_code - Tue May 30, 2006 2:12 pm

SteveH wrote:
You do relise that the DS screen is 256 pixels across or 32 tiles across, so to do horizontal scrolling you will need a 64x32 tile map, thus 2 map bases are assigned to the bg with that will be seamless, or if it's a bmp image you might be able to get away with a 256x256 image and update x columns (x = speed of scroll) per vblank, but it might be a tad slow to do...


i know... my point is to utilize the hardware, if there is a bg repeat. in the case there is no such thing, the 2 bgs solution is fine! (i didn't say it's crap or something!) now let's just forget about it, it's leading us nowhere until someone posts a bg repeat setup or simply proves there is no hw repeat.

#85449 - tepples - Tue May 30, 2006 2:22 pm

Yes, there is a background repeat for at least tiled backgrounds.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#85455 - silent_code - Tue May 30, 2006 2:55 pm

:D

and there are tools that "transform" a bmp image to a tiled map ;)

yet, you're right to use two bgs as it's easier to fill in non repeating bgs (like when your maps consist of many "screens"), but that can be done with one tiled bg, too (it needs to be wider than the screen, like e.g. 512 pixels or 64 tiles).

#86774 - knight0fdragon - Fri Jun 09, 2006 4:12 am

hey try this for wrap BG3_CR = BG_BMP16_256x256 | BG_WRAP_ON;
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#86837 - PacoChan - Fri Jun 09, 2006 8:01 pm

Wow, thanks knight0fdragon, it works perfectly. Now I don't have to use two bgs. That was exactly what I was looking for. ;)

#86853 - knight0fdragon - Fri Jun 09, 2006 10:58 pm

yea fiddleing around with what was available in video.h I came across that, glad it helps, now u can use another background for foreground effects or something
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#86925 - silent_code - Sat Jun 10, 2006 5:23 pm

thanks kOd!