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.

Newcomers DBPro Corner / When should images/sounds be loaded?

Author
Message
Alaror
13
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 25th May 2011 22:00
I had a quick question about code hierarchy and optimization. I've seen it suggested that you load all your images in a setup sub event, but wouldn't doing that result in you wasting resources, making the game run slower? Would loading them at another point, possibly at the first instances of that object type being created, have any unwanted consequences? Should sounds be handled differently?

Thanks in advance for your help!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th May 2011 23:05
Generally, I load resources at the earliest opportunity, subject to memory space.

For example, in a program where all resources can fit in memory at once, I load them at the beginning.

In a program where there isn't enough memory for all resources, and assuming a level-based game, I'd load everything for a level when I enter the level, and delete it when I leave the level (either ready for the next level or dying).

Object instances are something completely different - they don't count as resources (IMO), and should be created / deleted on demand, as they were designed for that purpose.

Others may do something different, but I think those are the most obvious options.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th May 2011 00:18
I tend to have Init() and DeInit() routines for menus, background sounds, bitmap fonts etc.

I then have GameInit() and GameDeInit() for game specific graphics and media.

These are the only places I load and unload entities, so it's easier to track down any issues.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 26th May 2011 05:18
Yeah it's better to load everything at the beginning so it's easier to see where all your images/sounds/music. For small projects I generally do it at the top right under any arrays but for larger projects I put them in a function but call it right under the arrays.

Login to post a reply

Server time is: 2024-11-16 21:37:23
Your offset time is: 2024-11-16 21:37:23