Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Vector sprites won't display. (2D Platformer)

Author
Message
Mikebissle
15
Years of Service
User Offline
Joined: 18th Oct 2009
Location:
Posted: 18th Oct 2009 15:58
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?
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 18th Oct 2009 17:24
Use code tags next time for your snippets. An where are the 'problematic' lines located in your main file? Showing us the whole entry point would be useful.

Quote: "Or it GDK not OO-friendly?"


How can anything not be OO friendly? It's not like GDK can know how you're using it.

Mikebissle
15
Years of Service
User Offline
Joined: 18th Oct 2009
Location:
Posted: 18th Oct 2009 17:37
I'm sorry, I don't know why the code tags didn't work the first time around. Here's the main file.

Mikebissle
15
Years of Service
User Offline
Joined: 18th Oct 2009
Location:
Posted: 20th Oct 2009 03:19
Here's the rest of my code--sorry, I've been busy.









Additionally I attached a screenie to show what's going on. Gravity and collision detection both work, and the game detects the tile that I made using a vector or tiles... but they don't display the sprites to the screen. I've noticed that when I did a dbSprite manually using the ID of the vector, they display, but on their own, the Sprite class constructor ignores the drawing.

Any idea what I did wrong here?

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-20 13:20:10
Your offset time is: 2024-11-20 13:20:10