Background image wierd

support for the ARM toolchain
Post Reply
feonx
Posts: 1
Joined: Wed Jun 22, 2011 12:44 pm

Background image wierd

Post by feonx » Wed Jun 22, 2011 1:17 pm

Hi,

At first, thanks for reading. I'm a beginner of programming voor de NDS and I try to put a image on the background of the main screen. On the internet I've found some example code but it only works with image at size of 256x192. I currently have the code as it needs to be, but I can't find out how to get a larger image as background.

If you wonder why I want a larger image as background, it's because I want to scroll the image from left to right. To draw the image on the screen I use:

Code: Select all

draw_bitmap(main_background, IMAGE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

void draw_bitmap(Color* background, Color* bitmap, s16 x, s16 y, s16 width, s16 height)
{
	s16 y_pos, x_pos;

	for(y_pos = 0; y_pos <  height; y_pos++)
	{
		for(x_pos = 0; x_pos < width; x_pos++)
		{
			draw_pixel(background, x + x_pos, y + y_pos, bitmap[(y_pos * width) + x_pos]);
		}
	}
}

inline void draw_pixel(Color* background, s16 x, s16 y, Color color)
{
	if(x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT)
	{
		background[(y * 256) + x] = color;
	}
}
The rest of the code can be found here: http://www.feonx.com/imageslide.rar
Can someone help me?

P.S: Sorry for my bad english.

Kind requards,

Feonx

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: Background image wierd

Post by zeromus » Sun Jul 03, 2011 2:59 am

you have things backwards.

you are always choosing the same 256x192 pixels from your source bitmap. you write
bitmap[(y_pos * width) + x_pos]
now consider what values y_pos and x_pos will take.

you are drawing out of bounds to your destination BG. you write
draw_pixel(background, x + x_pos, y + y_pos, (COLOR))
now consider what values x + xpos will take.

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests