-3

I am coding for the nds using Devkit pro in c++, and there is a graphic that is being displayed at the top. Each graphic is loaded with a value (Which is what part of an image it is loaded from), and I want to have about 20 graphics of the same type, but different values loaded and displayed at the same time. Is there a way to create some sort of an array of graphics instead of defining "graphic INV1; graphic INV2;" and loading them all? Each graphic is defined, loaded, and shown below:

graphic inv1;
graphic inv2;

if (loadedgraphic) unloadGraphic(&inv);  //basically reloads graphics
loadGraphicSub(&inv1,2,5);               //arguments: (Graphic, type, value)
loadedgraphicinv = true;

if (loadedgraphic) unloadGraphic(&inv);  //basically reloads graphics
loadGraphicSub(&inv1,2,6);               //arguments: (Graphic, type, value)
loadedgraphicinv = true;


showGraphic(&inv1,10,10); // This shows the inv1 graphics at the coordinate (10,10).
showGraphic(&inv2,10,15); // This shows the inv2 graphics at the coordinate (10,10).

And this would repeat maybe 20 more times with a new graphic each time...

Matthew D. Scholefield
  • 2,977
  • 3
  • 31
  • 42
  • 3
    Create a data structure to hold them, such as a list or a vector in the standard library. Create a function or class to manage the resources such as a graphic factory. –  Mar 20 '13 at 12:25
  • This is interesting, but I would still have to define and init every single one... Ultimately, I have 2 for loops that I want to have display the graphics, but each one different. So idealy, something similar to: graphic INV[]; //INIT INV for (x=0;x<20;X++) showgraphic(&INV[x],2,x) – Matthew D. Scholefield Mar 20 '13 at 12:51

1 Answers1

0
std::vector<graphic> vMyGraphics(7);
for(int i=0; i<7; i++)
{
   if (loadedgraphic) unloadGraphic(&inv);  //basically reloads graphics
   loadGraphicSub(&vMyGraphics[i],2,i+1);               //arguments: (Graphic, type, value)
   loadedgraphicinv = true;
}
fatihk
  • 7,789
  • 1
  • 26
  • 48
  • 1
    This code contains errors. You might run into seg-faults... You are accessing vMyGraphics before the element has been created. – Skalli Mar 20 '13 at 14:30
  • 2
    actually, I foound out, all I simply need to do (I'm not sure if this is project specific) is add [47] to make a graphic array of 47. – Matthew D. Scholefield Apr 02 '13 at 02:35