Sign in to follow this  

My new cApp, but how can I store images???

Recommended Posts

Ok, so I made a class cApp to handle input, events, initialization, deinitialization, and handling the screen including refreshing it and fliping it. I also made a class cApp_Sprite which can load an image, set a color key, set the x/y coordinates, and draw itself to the screen. For now I use GetVideoSurface() for it since m_Screen is private in cApp. My question: how do you suggest that I store all my cApp_Sprite's in my cApp dynamically? I mean removing them, adding them, etc. Now you can do something like this:
#include <SDL.h>

#include "cApp.h"
#include "cApp_Sprite.h"

#include <ctime>
#include <cstdlib>

int main(int argc, char *argv[])
    cApp theApp;


    theApp.InitWindow(350, 600, SDL_DOUBLEBUF | SDL_HWSURFACE);

    cApp_Sprite sprite1;

    sprite1.SetColorKey(7, 7, 7);
    sprite1.Setxy(76, 54);

        if (theApp.EventOn())
            if (theApp.GetEvent().type == SDL_QUIT)

        theApp.RefreshScreen((rand() % 0xFFFFFFFF) - (rand() % 0xabcdef12));

        if (theApp.GetKeys()[SDLK_ESCAPE])




    return 0;

That code is pretty much self explanatory. But I would like something like this:
theApp.AddImage("box.bmp"); // this is not implamented because I dont know how

How would I go about doing something like this? Dynamically? Here is cApp:
#ifndef C_APP_H
#define C_APP_H

#include <SDL.h>

#include <vector>
#include <string>

#include "cApp_Input.h"
#include "cApp_Event.h"
#include "cApp_Sprite.h"

class cApp: public cApp_Event, public cApp_Input
        std::vector<std::string> m_Errors;

        SDL_Surface *m_Screen;


        bool Init(unsigned int flags);
        bool InitWindow(int w, int h, unsigned int flags);
        bool DeInit();

        void PrintErrors();

        void RefreshScreen(int color = 0x00000000);
        void FlipScreen();

#endif /* C_APP_H */

Thanks to all. P.S. I forgot something: Compiler: MingW IDE: Code::Blocks API: SDL Language: C++

Share this post

Link to post
Share on other sites
Generally.. when you load a image, you have it located in the project directory, the one where your main.cpp is located.

There are some more sophisticated ways to store your files, for example, you could make a .rc, and hold your files internally. (Inside of the exe) Or you could make some sort of packfile system, and compress all your game files into a seperate file.

If you are adding a image for a sprite we sorta need to know what the sprite has in it. If it's a bunch of frames for a sprite then you'll need to clip the render of the sprite to create the illusion of a animation.

In any case, something like 'theApp.AddImage("box.bmp");' sounds a little out of place. I'd have a sprite object, and then a spritelist object that manages them on the screen. Really more of a how complicated you want it to be thing :P

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this