Hi guys. I started programming again after 8 months, and decided to give the GSK a shot. I'm trying to make a basic one screen platformer. It's OO, with so far just a Game class and a Sprite class. The problem is with the bolded constructor in the Sprite class.
class Sprite{
public:
Sprite();
//default constructor
Sprite(string,short,short);
//takes file name and coordinates
Sprite(string, short, short, short);
~Sprite() {dbDeleteSprite(ID); }
void Move (int dir, int xx, int yy);
void Tele (int xx, int yy);
void Hide ();
void Tile ();
bool Collison(int);
static int sprite;
//static int represents number of sprites on screen.
int h, w, x, y;
//dimensions and coordinates
string name;
//filename of picture
int ID;
//sprite ID
};
extern vector<Sprite*>Object;
//vector that contains all objects--used for collision detectiona and gravity;
Sprite.cpp
...
int Sprite::sprite = 0;
vector<Sprite*>Object;
Sprite::Sprite(string a, short xx = 0, short yy = 0): name(a), x(xx), y(yy) {
Object.push_back(this);
//adds sprite to object list
++sprite; ID = sprite;
//increments sprite number and assign sprite ID
dbLoadImage ((char*)name.c_str(), ID);
dbSprite(ID, x, y, ID);
w = dbSpriteWidth(ID); h = dbSpriteHeight(ID);
}
And the problematic part of my main file:
Sprite Cat ("Splash.png", 0, 0);
Sprite Cliff ("RockCliff.png", 0, 384);
Sprite Cliff2("RockCliff.png", 48, 384);
Sprite Cliff3("RockCliff.png", 96, 384);
vector<Sprite>Cliffs(2);
Cliffs[0] = Sprite("RockCliff.png", dbRND(SCREEN_W), dbRND(SCREEN_H));
Cliffs[1] = Sprite("RockCliff.png", dbRND(SCREEN_W), dbRND(SCREEN_H));
When I initialize the sprites like so, all the objects load to the screen, but the last two in the vector don't display. They are affected by the collision detection, so they are there, but the images aren't shown.
I'm basically trying to do class-based tiling. I tried with a vector, an array, a Tile class function, etc. When I used an array, all the tiles were invisible (but collidable), and the screen couldn't refresh so I saw the afterimage of the Cat sprite wherever I moved him.
And weirdly enough, moving the push back in the constrctor to the ends renders all sprites except the first and last invisible...???
I've only been using GDK for a few days, so I don't fully know what's going on. What am I doing wrong here? Or it GDK not OO-friendly?