Off Topic > Off Topic
Programming Megathread
<< < (162/241) > >>
Becquerel:
Bump
Glass Joe:
I recently got stuck while making a C++11/SDL game engine, and I can use some advice.
Ideally, what I want to do is the following:
1. create enumeration representing all sprites to add to a spritebank
2. create a vector of filenames, and using the enumeration add each filename to the vector
3. go through all loaded filenames, and using the enum create sprites with specific properties

but I can't quite find a way to do the second and third step without having my compiler belch a bunch of errors. Any ideas as to how to get it to work? The code I used is below (feel free to say if there's any info missing)


//application class that starts the program//
std::vector<std::string> files;

class App : public Event
{
    private:
        bool Running; //Running flag

        enum sprite_file
        {
            SPRITE_RING1 = 0,
            SPRITE_RING2 = 1,
            SPRITE_END = 2
        };

        SDL_Window* graphicsWindow; //The window
        SDL_Renderer* graphicsRenderer; //The renderer
        TTF_Font* globalFont; //The global font

        Timer capTimer; //Frames per second cap timer

        SpriteBank rings; //Collection of sprites
        std::string currentSprite; //Filename of sprite in use
[...]
//initialization function within App//
//Initialize spritebank
   if(!rings.Init(graphicsRenderer))
   {
      printf("Failed to load sprites!");
   }

   //Add two sprites
   files.emplace(SPRITE_RING1, "media/img/ring/ring1.png");
   files.emplace(SPRITE_RING2, "media/img/ring/ring2.png");

   //Add two sprites
   for(auto filename : files)
   {
      switch(this->sprite_file)
      {
         case SPRITE_RING1:
         {
            rings.AddSprite(filename,
                        40,
                        40,
                        40,
                        20,
                        20);
            break;
         }

         case SPRITE_RING2:
         {
            rings.AddSprite(filename,
                        40,
                        40,
                        40,
                        20,
                        20);
            break;
         }
         default: continue; break;
      }
   }

   currentSprite = SPRITE_RING1;


EDIT: The file.emplace() functions give this error, switch(this->sprite_file) gives this, and the alternative, switch(sprite_file) gives this
ZSNO:
I don't see where you declared 'files'
Also the compiler errors would be nice to see
Glass Joe:

--- Quote from: ZSNO on August 11, 2016, 04:08:33 PM ---I don't see where you declared 'files'
Also the compiler errors would be nice to see

--- End quote ---
stuff, my b for forgetting to include those things, I edited the main post to include them now
TristanLuigi:
My problem is that my attention span is only a few days so I can never get big projects done. Does anyone have any advice to stay motivated?
Navigation
Message Index
Next page
Previous page

Go to full version