NOTE: this is for my show and hide system for sprites.
Here is the code for the Sprite class:
Code: Select all
#include "Content.h"
using namespace std;
#ifndef SPRITE
#define SPRITE
class Sprite{
public:
Sprite();
Sprite(string file2,int x2,int y2,bool visible2);
void show();
void hide();
SDL_Surface *bmp;
string file;
int x;
int y;
bool visible;
};
Sprite::Sprite(){
file="null.bmp";
bmp=SDL_DisplayFormat(SDL_LoadBMP(file.c_str()));
x=0;
y=0;
visible=false;
}
Sprite::Sprite(string file2,int x2,int y2,bool visible2){
file=file2;
bmp=SDL_DisplayFormat(SDL_LoadBMP(file.c_str()));
x=x2;
y=y2;
visible=visible2;
}
void show(){
SDL_BlitSurface(bmp,NULL,screen,new SDL_Rect(x,y,NULL,NULL)); //3)width 4)height
}
void hide(){
SDL_FreeSurface(bmp);
delete this;
}
#endif
Code: Select all
void hide(){
SDL_FreeSurface(bmp);
delete this;
}
Wait!
I have another few errors. Now that I've fixed that I'm getting 'screen' has not been declared in this scope but 'screen' is declared in 'Content.h' which is being included into 'Sprite.h'.
Anywhoo here's 'Content.h':
Code: Select all
#ifndef CONTENT
#define CONTENT
#include <iostream>
#include "SDL\SDL.h"
#include "windows.h"
#include "Environment.h"
#include "Sprite.h"
#include "Tile.h"
#include "Map.h"
#include "World.h"
#include "Object.h"
#include "Creature.h"
#include "Npc.h"
#include "Player.h"
using namespace std;
int mapIndex=0;
SDL_Surface *screen=NULL; //SDL's screen
Sprite *sprite=new Sprite("dude.bmp",10,10,true); //test sprite
Player *player=new Player(); //Main Player
World *world=new World(); //the world
#endif