Page 1 of 1

Global sprites only or is there another way?

Posted: Sat Apr 19, 2008 1:53 pm
by Foz
I want to load some sprites, but I have four sections of the app that I am making, and these sprites are dedicated to each section - the sprites don't over lap sections.

That's all fine, but I have before the main game loop four data loading procedures, one for each section, and then it goes into Section1() which then holds a game loop until a selection is made to send it into Section2, Section3 or Section4 loop.

The thing is that currently I have to hold all the sprites as globals so they can be loaded in one procedure upfront and then actually used in other procedure, and now I'm getting a lot of them.

Coming from the school of thought that globals are a Bad Thing(tm) is there a better way of partitioning the variables for cases such as this, or is this the beauty of procedural programming that keeps things fast?

Posted: Sat Apr 19, 2008 2:22 pm
by Booger
Its not a bad thing to hold all the sprites you are going to use as global, unless you are short on Video memory or system memory.

Purebasic keeps a copy of your sprite in system memory for pixel and collision tests.

If you don't wanna do that, then delete your used sprites after each section and reload the new ones.

Posted: Mon Apr 21, 2008 1:23 am
by citystate
you could use static variables in the various procedures... sort of a compromise between global and local... not sure of the overhead this would create though

Posted: Mon Apr 21, 2008 10:16 am
by Foz
I thought that, but to keep the code clean, I want to keep the loading code separate from the actual game loop, so it can go in it's own Initialise file.

What this really boils down to is me coming from an OOP point of view, where variables are class level rather than global.

*shrugs*

It's nothing serious, I'll just give set prefixes to my variables. It would just be nice, that's all.