Global sprites only or is there another way?

Advanced game related topics
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Global sprites only or is there another way?

Post 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?
Booger
Enthusiast
Enthusiast
Posts: 147
Joined: Tue Sep 04, 2007 2:18 pm

Post 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.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post 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
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post 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.
Post Reply