Posted: 7th Dec 2011 11:36
Hello, is there a way to delete all images/sprites/sounds/musics in AppGameKit?

As the autocreated id's start at a number I don't currently know, I can't create a for/next loop to delete them. Just wondering if there's an undocumented way of deleting all loaded media?

I'll create an entry in the bug/request board anyway.
Posted: 7th Dec 2011 13:29
That would be a handy command seconded...

Currently I have to store everything created. That data is already stored somewhere by AppGameKit so we are having to create wasted memory to effectively use it.
Posted: 7th Dec 2011 13:32
Mobiius, all this deleting media, memory leaks etc etc confuses the hell out of me... If you don't mind me asking (I don't want to hijack your post), why would you need to delete media? All I do is create a sprite and then move it on screen as and when I need it... Is that not right? I've never even thought about deleting media, if I don't need something to be displayed, I simply move it off screen. Am I going the wrong way about things? (I'm new to this if you haven't guessed, and would like to get rid of my bad habits early!!)... Thank you!
Posted: 7th Dec 2011 13:59
Mobiius:
I would say it's better to keep track of the media you need to delete rather than deleting everything. Reloading media is inefficient. Using variables to keep track of your media makes this a whole lot easier than keeping track of numbers yourself.

Funnell:
You don't need to move sprites outside of the screen. You can change their visibility with SetSpriteVisible(). Depending on the size of your project, deleting media might be a good idea to save memory. In a large project you might consider loading, deleting and loading more media. However, AppGameKit will automatically delete your media for you when you end the program.
Posted: 7th Dec 2011 14:15
Thanks Digital Awakening... I guess thats the difference, my projects are not that large. I simply load everything up front and then use it as and when I need it. In other words, once the game has loaded, everything has been created, I never perform any 'Create' or 'Load' commands in the 'Loop'...

As for the invisibility thing, I done that originally, but found that the sprite is still actually there and influences things like 'GetpriteHit' etc... Thats when I opted for moving them off screen, that way, they can never get touched...

Thanks again...
Posted: 7th Dec 2011 14:50
Yes if you are checking SpriteHits then making sprite invisible is not enough, you need to move it outside the screen.
Posted: 7th Dec 2011 16:41
Currently I have to store everything created.

Yes, so am I. I had to change the way my game engine works to accommodate it. But at least I can now return every image used in an animated sprite. (GetSpriteImageID() only returns one image so is useful only for animations with atlas images. Animations created with multiple images don't return every image with that command, only the current frame)

why would you need to delete media?

Image I have a level. This level has 200 images and 400 sprites.

Now imagine I have 8 of these levels, and each level doesn't use the same images. (Because, for example, one is a lava level, one is an ice level, and they don't share images for this reason) There would be a lot of images loaded onto a device which were not being used.

I'm from the programming school which loads only what's needed, then clears up when I've done with it. Memory is precious!

Reloading media is inefficient.

So is retaining unused media in memory "just in case"
Posted: 7th Dec 2011 16:49
"


Point taken! Thanks! I'm a self-taught coder (a very recent one at that), information like this is much appreciated. I'm working on a game which probably has only about 200 images for the whole thing which I guess is why I haven't experienced memory issues...
Posted: 7th Dec 2011 17:11
I haven't experienced memory issues either. And coding like I do, I hope I never will! Lol
Posted: 7th Dec 2011 17:33
I did this once,

+ Code Snippet
 For i= 1 to 1000000 (Or any hig number)
    If GetSpriteExists(i)
        DeleteSprite (i)
    Endif
Next i


And the same thing with all buttons, texts ect.
Posted: 7th Dec 2011 19:24
I tried that, but with the more specific:
+ Code Snippet
For I = 10000 to 20000
    If GetSpriteExists( I ) Then DeleteSprite ( I )
Next I

But I got a "GAME.exe has stopped working" error. So I changed it.
Posted: 7th Dec 2011 19:30
Mobiius:
If I were you I would load all the level images into an array, something like this. It would then be easy to delete all these images without deleting stuff like player or HUD images.

+ Code Snippet
dim levelImage[200]
count = 0
file = OpenToRead( "level-01.txt" )
while FileEOF(file) = 0
   levelImage[count] = loadImage( readLine(file) )
   inc count
endwhile
Posted: 8th Dec 2011 1:06
I rather like the idea of a universal DELETE ALL command. If someone would add it as a feature request in the issues board it might just make an appearance in a future build: http://code.google.com/p/agk/issues/list
Posted: 8th Dec 2011 15:58
If someone would add it as a feature request

I did, as soon as I made the original post! lol

I'll create an entry in the bug/request board anyway.

See.
Here's the link to it, and it's already been accepted.
http://code.google.com/p/agk/issues/detail?id=175


If I were you I would load all the level images into an array, something like this

My existing code wouldn't support this without some major recoding. (My UI code is all plug and play, just add the agc file and your done.) This method would not be plug and play enough.

I did however come up with a way to save the images to a typed array after loading with the original UI code so I'm good to go. As I'm still developing, I haven't implemented it yet, but it'll work in theory!