Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Efficiency: delete sprite or hide sprite?

Author
Message
Kerl
User Banned
Posted: 18th Mar 2012 00:42
Hello all,

I am currently working on a 2D game pause menu and I have a few questions about how would be the most efficient way to handle reoccurring images.
Is it more efficient to delete sprite images when they are being used and then re define them when they are used or to just hide them until they are needed again?

For instance I have a pause menu that brings up a background and a couple of text sprites. When the player chooses to return to the game should I delete these sprites or just hide them?
Also if the player chooses to exit to the main menu to restart the game THEN should I delete the sprites or still continue to hide them?
WLGfx
12
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Mar 2012 05:23
For a pause menu it shouldn't make much difference really as you're not after a fast frame rate to keep the screen updated, so my guess is creating them and deleting them shouldn't make any difference in game. Possibly even to loading the sprites from a hard disk wouldn't make much difference either.

If you're changing fonts to create the sprites then it's probably best to check the speed differences out by making a quick test program in DBPro and compare it to pre-created sprite images stored on the hard disk and see which would be quicker.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Kerl
User Banned
Posted: 18th Mar 2012 05:40
Thanks for the reply. I see what you're saying, most simple things like that shouldn't make a big difference. Currently I am using using sprites for most of my text display instead of dbfont.

Now that you mention it, I was wondering how to go about testing code for efficiency methods. Say you want to A - B test 2 different ways of accomplishing 1 task, how you would be able to tell which one is "better?" I know better is a subjective word, but perhaps which code uses less CPU or memory.
WLGfx
12
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Mar 2012 08:57
There's little difference between DBPro and Dark GDK, so if you have DBPro, or even have the free version then just proto-type some parts of your code. DBP does have the PerfTimer() which will give you an accurate'ish timing between point A and point B in a program. Although the best way to time efficiency short term is to run a piece of code many times.

I do know that when setting up a new font in DBP and GDK it takes a while to initiate the new font ready for drawing. Not noticeable in a single glimpse but swapping and changing many times during fast screen updates drastically slows things downas it frees up the memory used by the old font and then sets up a new one. It will set up memory for each character in the font even if you're only using one letter from it.

Usually I would use 3 functions (or 3 base methods if it's a class), init() which sets up the images, data, etc. while ( run() ) which keeps calling the main function until it's finished doing it stuff or the user has clicked something. And close() which free up any used resources. The same could be done for the pause menu. Init() would setup the data (whether coded created or pre-created files). Neither would actually use the most memory really unless you're using dbFonts to draw large text.

Pre-created images on disk may be faster but would take up file space where-as code created may take a little longer depending on the size of the fonts being used...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2020-09-24 21:52:35
Your offset time is: 2020-09-24 21:52:35