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.

Coding > clearing screen

#34874 - blinky465 - Thu Jan 27, 2005 5:05 pm

I'm almost done with my iso game which uses tiled backgrounds for the floor tiles (Scott's suggestion in the iso games topic) and a linked list of sprites for the on-screen characters. I'm using VisualHAM for creating tiled backgrounds and sprites.

When I come to clear the screen, I loop through my linked list finding the corresponding sprites and I delete each one (freeing up resources as I go) and then remove the two tiled backgrounds.

As the tiled backgrounds are removed, there's a definite "chequering" effect as one is removed, then the other. I would like to avoid this.

So I created a "curtain" effect by using the DMAClearScreen function suggested on an earlier post:

Code:

void DMAClearScreen(u16 color) {
   ham_VBAText("clearing screen");
   REG_DM3SAD     = (u32) & color;
   REG_DM3DAD     = 0x06000000;      //Destination Address
   (REG_DM3CNT_L) = (160 * 240);
   (REG_DM3CNT_H) = 0x9100;
}


So now I call this clear function using DMAClearScreen(0);
my screen goes black instantly and then I tidy up the sprites etc.
But the screen never returns from black!

The screen is recreated and the game continues (since after a little while, my main character dies and I get taken back to the menu screen) so I wondered if there was something I was missing:
a call to the function is indeed copying just a big black square directly into the video ram buffer - but any drawing functions after this don't seem to have an effect.

Do I need to do anything before setting background tiles and drawing more sprites?

#34875 - poslundc - Thu Jan 27, 2005 5:21 pm

The function you've listed is designed to clear the screen in bitmap modes, not tile modes. It ostensibly works because you are overwriting the same VRAM you use for tiles with zeros, but in practice you are overwriting the tile data you're using as well as the map data.

If all you want to do is blank the map out, you can do any of the following:

- Set the tiles in the map to a special blank tile
- Set all of the colours in the palette to the same colour
- Overwrite the tile data with zeros (what you've basically done here, but then you've lost your tiles)
- Turn the background off

If you want a smoother transition to black, either use the effects register to fade in or out over a period of time (or do a palette fade if you want and know how) or use a window and change its dimensions over a period of time.

Dan.

#34877 - Datch - Thu Jan 27, 2005 5:31 pm

Which mode you're using? This look like a mode 4 code clear method.

In a tile mode, I guess you could use a black square sprite scaled to the whole screen. Then you could clean up all the other sprites and even build up another screen before removing your black square sprite. (I've never tryed that though =) )

#34885 - blinky465 - Thu Jan 27, 2005 8:47 pm

Datch wrote:
In a tile mode, I guess you could use a black square sprite scaled to the whole screen. Then you could clean up all the other sprites and even build up another screen before removing your black square sprite.


I like the sound of this - put the curtain up, draw the screen, pull it down. Play the game. Curtain up, clear the screen, pull it down.

Is is possible to quickly stretch a single sprite to fit the whole screen? (my main sprites are 16x16) Or would I need to tile 12 64x64 sprites?

I'm using bg mode 0.
Thanks- Chris


EDIT - don't know why I didn't do this - I just made the background invisible before deleting the linked list. It's not brilliant but will do for now - I'd still like to use the big sprite idea - and may be fade it down (alpha 100% to 0%) to give the illusion of the game screen fading up from black.


Last edited by blinky465 on Thu Jan 27, 2005 8:53 pm; edited 1 time in total

#34886 - tepples - Thu Jan 27, 2005 8:52 pm

A single sprite cannot be stretched larger than 128x128 pixels (i.e. a 64x64 pixel sprite in double size mode).

Super Mario Bros. 3 for NES does a convincing curtain effect without any scaling hardware.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#34887 - poslundc - Thu Jan 27, 2005 9:15 pm

blinky465 wrote:
EDIT - don't know why I didn't do this - I just made the background invisible before deleting the linked list. It's not brilliant but will do for now - I'd still like to use the big sprite idea - and may be fade it down (alpha 100% to 0%) to give the illusion of the game screen fading up from black.


Using sprites for this purpose is an extremely inefficient use of resources. You can darken or lighten a layer to fade to or from black using the effects register. Or you can use any of the other techniques I mentioned in my post.

Dan.

#34888 - DekuTree64 - Thu Jan 27, 2005 9:28 pm

I'd recommend using a window instead, they're much easier. Just turn everything off inside the window, everything on outside, and move the bottom coordinate down every frame.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku