DSLua Community
Welcome, Guest. Please login or register.
May 21, 2012, 07:52:50 PM
1371 Posts in 262 Topics by 33109 Members
Latest Member: Limewire Download
DSLua Community  |  DSLua - Best scripting language for Nintendo DS  |  Need Help?  |  Loading/Unloading Backgrounds and Sprite Dominance « previous next »
Pages: [1]
Author Topic: Loading/Unloading Backgrounds and Sprite Dominance  (Read 2930 times)
sylus101
Waxing Crescent
**
Posts: 68



« on: March 15, 2007, 04:42:56 PM »

Greetings everyone!!

Things are moving along well, and I've got some quick questions.

When loading a new background, is there a way to "free" the previous one like a sprite is freed with Sprite.Free()? Currently I just run all the same commands pointing to a different map pal and raw file and that seems to work but I wonder if I have a memory leak there.  Huh

Also, I'm trying to see what causes one sprite to be drawn on top of another. I've played with order of loading and palette number with varying results. Is there a tried and true way to control this?
« Last Edit: March 15, 2007, 04:49:02 PM by sylus101 » Logged
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #1 on: March 16, 2007, 12:46:52 AM »

I was wondering this too since I'm making a game with lots of different background maps. So I remembered CPU_Smarts' point-and-click game, which has a lot of backgrounds. (This is probably the only place you can download it anymore: http://gchack.free.fr/DS/homebrew/SunsetResort/SunsetResort.zip .) What he did was load his new background into the same variable as his old one. An example:

Code:
-- Load Bottom Screen

BGBottomMap:LoadPalette( "DS-bottom.bmp.pal" )

BGBottomMap:LoadTiles( "DS-bottom.raw", 256 )

BGBottomMap:LoadMap( "DS-bottom.map", ( 256 / 8 ), ( 192 / 8 ))

Screen.Initialize( SCREEN_BOTTOM, BGBottomMap )

-- (touch the screen to continue)
while not Stylus.Down() do end


-- Load new background to bottom screen
BGBottomMap:LoadPalette( "DS-bottom2.bmp.pal" )
BGBottomMap:LoadTiles( "DS-bottom2.raw", 256 )
BGBottomMap:LoadMap( "DS-bottom2.map", ( 256 / 8 ), ( 192 / 8 ))
Screen.Initialize( SCREEN_BOTTOM, BGBottomMap )

He has over 30 background maps in the game, and when I played it there didn't appear to be any problems.

And the sprites, for now, will be on top of each other in the order that they are created. Eventually DSLua should let you choose which ones will go on top of each other.
Logged
TOAST
Waxing Crescent
**
Posts: 67



« Reply #2 on: March 16, 2007, 10:03:07 AM »

And the sprites, for now, will be on top of each other in the order that they are created. Eventually DSLua should let you choose which ones will go on top of each other.
You already can, it depends on which order you create them in.
Or did you mean something like swapping depth later in game?? So far there's no faster way than freeing the sprite and creating it again with Sprite.Create().
Logged
sylus101
Waxing Crescent
**
Posts: 68



« Reply #3 on: March 16, 2007, 11:18:28 AM »

Will do on the Backgrounds.

I'll run a few more test with the sprites, it seemed to be erratic but I could have been freeing and creating in some kind of off order.

Thanks again everyone!
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #4 on: March 16, 2007, 04:12:10 PM »

Sylus, TOAST, and jeremy:

Note about the Backgrounds: I found that and tried to create a video player (each frame was in a seperate map file), and noticed that that does NOT replace the background, it just appears OVER it. After about 70 frames, the program crashed with an allocation error.  Undecided

Edit: And jeremy, your Skydiver 3 crashes after you play so many times for the same reason @.@
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
TOAST
Waxing Crescent
**
Posts: 67



« Reply #5 on: March 16, 2007, 07:36:48 PM »

Ouch, then you'll have to free and recreate?? Also clear screen.
Logged
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #6 on: March 17, 2007, 12:21:26 AM »

I don't think there's a Free function for backgrounds in DSLua yet... but according to PAlib you may not need one. There's a PAlib function to delete backgrounds from memory but it says that when you load a new background the old one will be automatically deleted. ( http://www.palib.info/Doc/PAlibDoc%20Eng/group___bg_tiles.html#ga6 )
Logged
sylus101
Waxing Crescent
**
Posts: 68



« Reply #7 on: March 17, 2007, 03:54:54 AM »

Note about the Backgrounds: I found that and tried to create a video player (each frame was in a seperate map file), and noticed that that does NOT replace the background, it just appears OVER it. After about 70 frames, the program crashed with an allocation error.  Undecided

Was this with or without defining a different variable each time? I can't say I know if it'd make a difference, but I was just curious.
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #8 on: March 17, 2007, 08:44:56 AM »

It didn't seem to matter wether it was a different variable or not. It crashed at the exact same frame both ways.

And btw, this post made on Linux Ubuntu 6.06! I haven't given up Windows YET (I'm running Ubuntu off a CD), but I might just do it if it keeps this up!
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
jester
Waxing Crescent
**
Posts: 86


Jester Corp DS Logo


WWW
« Reply #9 on: March 17, 2007, 08:27:31 PM »

Yes i had found this out the hard way

Also sometimes the next background and the one it is replacing may muddle up the screen!
Logged

CURRENT PROJECT:

JesterCorp DS- 2D FIGHTING GAME!!! Due out August 19th 2007!!!Having Sprite Issues but Toast is helping me ALOT
sylus101
Waxing Crescent
**
Posts: 68



« Reply #10 on: March 19, 2007, 06:10:17 PM »

OOoookay. I'm stuck.

chimera.zip

I can't figure out why the sword is always appearing behind the chimera. Just use A and B to use sword and Start to close.
(The attack grid is working, but just clutters up the test so I omitted it for now).

HELP!

*Edit - Well it appears I've got it figured out. I guess first loaded is most dominant (on top) and so on down. I found I could load the sword first on frame 0, leave that blank, and then just cycle frames after that.
I'm sure I'll have to play with Sprite.Create and Free to save memory when the need arises.
« Last Edit: March 23, 2007, 12:04:23 PM by sylus101 » Logged
suloku
New Moon
*
Posts: 8


« Reply #11 on: June 19, 2007, 09:53:44 AM »

Is the background limit still there? I mean, backgrounds are still in memory with no known way to unload/replace them?

I don't need anything like 70 backgrounds, but it may be very interesting to solve this.
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #12 on: June 19, 2007, 10:03:48 AM »

Well, if you're using DSLua 0.7, you can load raw BMP, JPG, or GIF images as 16-bit backgrounds, and use the :Clear() subfunction to free it.
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #13 on: June 19, 2007, 02:39:12 PM »

Well, if you're using DSLua 0.7, you can load raw BMP, JPG, or GIF images as 16-bit backgrounds, and use the :Clear() subfunction to free it.

That doesn't really free any memory, you just have to set your variable holding the image to imagevariable = ""
Logged
suloku
New Moon
*
Posts: 8


« Reply #14 on: June 19, 2007, 02:48:49 PM »

Well, if you're using DSLua 0.7, you can load raw BMP, JPG, or GIF images as 16-bit backgrounds, and use the :Clear() subfunction to free it.

That doesn't really free any memory, you just have to set your variable holding the image to imagevariable = ""

I think this doesn't apply to maps right? Just for the new iamge files that can be opened by 0.7 version, which anyway is good to know how to free them.

BTW, Jeremysr, I added you to msn two days ago because I saw that you have your adress for "contact". I wanted to ask you something, but I forgot (I must already figured out or something :S)
Logged
Pages: [1]
« previous next »
    Jump to: