DSLua Community
Welcome, Guest. Please login or register.
May 18, 2012, 08:52:44 PM
1371 Posts in 262 Topics by 33109 Members
Latest Member: Limewire Download
DSLua Community  |  General DS Programming Chats  |  Code Hashing  |  background image change? « previous next »
Pages: [1]
Author Topic: background image change?  (Read 2206 times)
angor
Waxing Crescent
**
Posts: 45


WWW
« on: May 08, 2006, 04:26:15 PM »

I have found the following issue. Could anybody help here?

1) I create a background image and initialize the screen -> OK
      g_BGTopMap = Screen.LoadTileBG()
      g_BGTopMap:LoadPalette( "./img/splash1.pal" )
      g_BGTopMap:LoadTiles( "./img/splash1.raw", 256 )
      g_BGTopMap:LoadMap( "./img/splash1.map", ( 256 / 8 ), ( 192 / 8 ) )
      Screen.Initialize( SCREEN_TOP, g_BGTopMap )

2) Later on, i want to change the background screen and i do: -> NO OK
      g_BGTopMap = Screen.LoadTileBG()
          g_BGTopMap:LoadPalette( "./img/snowBG.pal" )
          g_BGTopMap:LoadTiles( "./img/snowBG.raw", 256 )
          g_BGTopMap:LoadMap( "./img/snowBG.map", ( 256 / 8 ), ( 192 / 8 ) )
      Screen.Initialize( SCREEN_TOP, g_BGTopMap )

3) But if i use a new variable, it works!!: ->OK
      g_BGTopMap2 = Screen.LoadTileBG()
          g_BGTopMap2:LoadPalette( "./img/snowBG.pal" )
          g_BGTopMap2:LoadTiles( "./img/snowBG.raw", 256 )
          g_BGTopMap2:LoadMap( "./img/snowBG.map", ( 256 / 8 ), ( 192 / 8 ) )
      Screen.Initialize( SCREEN_TOP, g_BGTopMap2 )

Why i cannot reuse use the old variable? do i have to free it before reusing it? how?
I does not make sense to use different variables all the time (and consuming scarce memory...)

Thanks in advance
Angor

Logged
waruwaru
Administrator
Waxing Crescent
*****
Posts: 78


« Reply #1 on: May 08, 2006, 05:18:36 PM »

The tile backgrounds have resources associated with them (the palettes/tile images/maps), so, it's best to clean them up if you don't need them.  Maybe I should include a special background resource free function.  Right now, the best you can do is to get rid of the background and make garbage collection happen.  Try set g_BGTopMap to nil and setting the garbage collection limit to 0 to force garbage collection.  Let me know if that doesn't work.  I can create a delete or reset function for backgrounds.

Waruwaru
Logged
angor
Waxing Crescent
**
Posts: 45


WWW
« Reply #2 on: May 08, 2006, 05:36:32 PM »

The tile backgrounds have resources associated with them (the palettes/tile images/maps), so, it's best to clean them up if you don't need them.  Maybe I should include a special background resource free function.  Right now, the best you can do is to get rid of the background and make garbage collection happen.  Try set g_BGTopMap to nil and setting the garbage collection limit to 0 to force garbage collection.  Let me know if that doesn't work.  I can create a delete or reset function for backgrounds.

Waruwaru

Tested and:
a) just reseting the variables (=nil) does not work -> black screen
b) reseting the variables and forcing garbage collection -> it works but a noticeable screen blink (screen goes  black and then initializes with the second image)

So, all clear to continue using multiple screens for the Snowball battle game (the new version i am working on is far more attractive!!). Thanks a lot for the fast and effective feedback! Smiley
 
It would be nice in the future to have a more elegant solution (than the garbage collection). Examples:

- to add a .free() function to the screen variable or
- to allow overwite of screen variable palettes/tile images/maps with the currently existing funtions

Angor

Logged
waruwaru
Administrator
Waxing Crescent
*****
Posts: 78


« Reply #3 on: May 08, 2006, 06:28:38 PM »

It would be nice in the future to have a more elegant solution (than the garbage collection). Examples:

- to add a .free() function to the screen variable or
- to allow overwite of screen variable palettes/tile images/maps with the currently existing funtions

Thanks for testing and confirming the work-around!  Actually, the current code was written with the "overwrite screen variable" in mind.  Try this:

1)   g_BGTopMap = Screen.LoadTileBG()
      g_BGTopMap:LoadPalette( "./img/splash1.pal" )
      g_BGTopMap:LoadTiles( "./img/splash1.raw", 256 )
      g_BGTopMap:LoadMap( "./img/splash1.map", ( 256 / 8 ), ( 192 / 8 ) )
      Screen.Initialize( SCREEN_TOP, g_BGTopMap )

2) When you are ready to change backgrounds, just do the following:
          g_BGTopMap:LoadPalette( "./img/snowBG.pal" )
          g_BGTopMap:LoadTiles( "./img/snowBG.raw", 256 )
          g_BGTopMap:LoadMap( "./img/snowBG.map", ( 256 / 8 ), ( 192 / 8 ) )

See if that works better.  DSLua will de-allocates the resources when you call the Load* functions the second time around.

Thanks,
Waruwaru
Logged
angor
Waxing Crescent
**
Posts: 45


WWW
« Reply #4 on: May 08, 2006, 07:30:37 PM »

Tested both in Dualis and hardware

1)  By using the Screen.LoadTileBG() funtion only the first time, the black screen does not longer appear. There is still however a noticeable image blink in the change between the old image and the new one

2) The blink can be minimized greatly by adding a Screen.WaitForVBL() just before the change.

Thanks for the feedback!!

Angor

Logged
Zhen
Waxing Crescent
**
Posts: 45


WWW
« Reply #5 on: May 09, 2006, 05:46:22 PM »

Another think that can be added to DSLua for hide blinks is FadeOut -> Make Changes -> FadeIn.

It can be done in the NDS hardware?

Zhen
Logged
waruwaru
Administrator
Waxing Crescent
*****
Posts: 78


« Reply #6 on: May 09, 2006, 06:05:45 PM »

Another think that can be added to DSLua for hide blinks is FadeOut -> Make Changes -> FadeIn.

It can be done in the NDS hardware?

Zhen

Fade out can be done just by modifying the palette's RGB value (unfortunately, there isn't one with TileBackGround yet).  I can add palette access/fade function in the future versions.

Another thing I can do is to separate out the cf/gbfs read access from palette/tile/map setting, that should reduce the "blink" in theory.

Thanks,
Waruwaru
Logged
Zhen
Waxing Crescent
**
Posts: 45


WWW
« Reply #7 on: May 12, 2006, 02:13:50 PM »

I was looking for in documentation for the GBA, and I found that the Backgrounds can be disabled/enabled. Well, is not a Fade, but it can be util too.

For blink avoid or other graphic effects.
Logged
Pages: [1]
« previous next »
    Jump to: