C++, SDL and Inheritance question.
Moderator: Coders of Rage
- epicasian
- Chaos Rift Junior
- Posts: 232
- Joined: Mon Feb 22, 2010 10:32 pm
- Current Project: Gigazilla Engine
- Favorite Gaming Platforms: Dreamcast, SNES, PS2, PC
- Programming Language of Choice: C/++
- Location: WoFo, KY
C++, SDL and Inheritance question.
Okay, I'm stumped. I have a class named tnt_SpriteAnimation which derives from the class tnt_Sprite. In main, I create a new instance of tnt_SpriteAnimation (called test), which in the constructor, takes a file name argument, width and height. When I try to draw the sprite to the screen, I get nothing. However, if I change the instance "test" to a tnt_Sprite, I see the sprite sheet rendered to the screen. Why if the type is tnt_Sprite the sprite sheet is rendered and not rendered if the type is tnt_SpriteAnimation?
All help is greatly appreciated,
~EpicAsian
All help is greatly appreciated,
~EpicAsian
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: C++, SDL and Inheritance question.
Do you have virtual functions in your base class? because they could of been overwritten e.g.
Code: Select all
class tnt_Sprite {
virtual void render() { // render, render, render };
}
class tnt_SpriteAnimation : public tnt_Sprite {
void render() { // nothing };
}
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: C++, SDL and Inheritance question.
Also, rather than naming everything tnt_*, you should look into namespaces for your library/engine.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- epicasian
- Chaos Rift Junior
- Posts: 232
- Joined: Mon Feb 22, 2010 10:32 pm
- Current Project: Gigazilla Engine
- Favorite Gaming Platforms: Dreamcast, SNES, PS2, PC
- Programming Language of Choice: C/++
- Location: WoFo, KY
Re: C++, SDL and Inheritance question.
GroundUpEngine wrote:Do you have virtual functions in your base class? because they could of been overwritten e.g.
Code: Select all
class tnt_Sprite { virtual void render() { // render, render, render }; } class tnt_SpriteAnimation : public tnt_Sprite { void render() { // nothing }; }
Thank you, GroundUpEngine, I knew I mus have missed something obvious (again). That usually happens when I'm tired .
I never really though of using namespaces, I'll look into it.Ginto8 wrote:Also, rather than naming everything tnt_*, you should look into namespaces for your library/engine.
Thanks for all the help,
~EpicAsian
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: C++, SDL and Inheritance question.
No prob namespaces?
main.cpp
Code: Select all
namespace tnt
{
class Sprite {
// stuff
};
}
Code: Select all
using namespace tnt;
Sprite playa; // Now I can use tnt::Sprite
- epicasian
- Chaos Rift Junior
- Posts: 232
- Joined: Mon Feb 22, 2010 10:32 pm
- Current Project: Gigazilla Engine
- Favorite Gaming Platforms: Dreamcast, SNES, PS2, PC
- Programming Language of Choice: C/++
- Location: WoFo, KY
Re: C++, SDL and Inheritance question.
I know what namepaces are, I just never really thought about using them with the engine. :DGroundUpEngine wrote:No prob namespaces?
main.cppCode: Select all
namespace tnt { class Sprite { // stuff }; }
Code: Select all
using namespace tnt; Sprite playa; // Now I can use tnt::Sprite
~EpicAsian
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: C++, SDL and Inheritance question.
Well you should.epicasian wrote:I know what namepaces are, I just never really thought about using them with the engine. :DGroundUpEngine wrote:No prob namespaces?
main.cppCode: Select all
namespace tnt { class Sprite { // stuff }; }
Code: Select all
using namespace tnt; Sprite playa; // Now I can use tnt::Sprite
~EpicAsian
The entire reason C++ introduced namespaces was because every C library appended its own little prefix to all of their global function calls. OpenGL:
Code: Select all
glSOMESHIT();
Code: Select all
SDL_SOMESHIT()