Skip to main content
GameDev.net gamedev.net
🔒 Locked

Question.

Started by valsar Sep 21, 2007 at 3:01 AM 2 replies 650+ views
Original Post
valsar
valsar
I'm currently working on a 2d rpg. I'm programming in C++ and using SDL for graphics. Currently I've got a map displayed and a character walking around with no animation. I have the SDL_Surfaces for the map and the character declared global and it works fine. My question is that if I create an object for an object based on my sprite class, would it be a good idea to create a new surface, load the image and all that in the constructor or have them all declared globally. If it's a better idea to create them all in the constructor, how would I go about using that surface(s) elsewhere in my code if I needed to use it, such as the destructor to delete the surface.
superpig
superpig
You'll generally want to load all your graphics before the game starts, and yet you may be creating game objects throughout the level (e.g. in response to a trigger of some sort). So in your position I'd set up an 'image library' class that can load all the images into memory as SDL_Surfaces, and then have your game objects share those surfaces. The library becomes the only thing responsible for loading and deleting surfaces.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
valsar
valsar
Sorry for bringing this topic back, but I've been without internet for awhile and I'm just getting to see it now.

Do you think I could get some examples of how I would code the 'image library' class.

That's all I can think of for now, if I think of anything else, I'll post again.
pulpfist
pulpfist
A small tutorial

Stuff these utility functions into a source/header file pair, and you got a tiny SDL image library

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.