Graphics in c++ coded inefficiently

387 Views Asked by At

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

1

There are 1 best solutions below

2
fatihk On
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;
}