How to draw all instantiations of a class?

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
User avatar
Bullet Pulse
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 89
Joined: Sun Feb 21, 2010 6:25 pm

How to draw all instantiations of a class?

Post by Bullet Pulse »

I'm trying to write a function in my image class that will draw every instantiation of an image object to the screen, so that I won't have to put

Code: Select all

image1.DrawToScreen( surface );
image2.DrawToScreen( surface );
...etc
I'm using SDL by the way.
How would I go about doing this?
Image
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: How to draw all instantiations of a class?

Post by Moosader »

Hey theres--

Usually in my ImageManager class I'll store all the images as an array, then when I go to draw everything I call imageManager.Draw(); in main (or wherever), and it does a for loop through every index of the array, drawing each.
User avatar
Bullet Pulse
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 89
Joined: Sun Feb 21, 2010 6:25 pm

Re: How to draw all instantiations of a class?

Post by Bullet Pulse »

Alright thanks :D
Image
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: How to draw all instantiations of a class?

Post by Bakkon »

Look into the STL containers such as list and vector.
Post Reply