|
I can't assign a returned bitmap pointer |
Zanmoto
Member #8,665
May 2007
|
I am making a prototype for a 2D fighting game in C++ using allegro, but I am having trouble incorporating classes into it. I have narrowed the one function in my kCharacter class to BITMAP *kCharacter::Walk () In int main (), the code I have for assigning this bitmap is kCharacter * Player1; //Player1 class if (key[KEY_LEFT]) I'm not really sure what is going on. I have CharacterImage declared in kCharacter and I have it initialised in the constructor. What happens is, the text I have in the code before the if statement works grand, but then when it gets to the if statement windows experiences a problem with the applicatino a closes it down. Any help would be appreciated, thanks. P.S. Please don't flame me. |
X-G
Member #856
December 2000
|
More code. -- |
Zanmoto
Member #8,665
May 2007
|
Steve.h #include <allegro.h> class CCharacter CCharacter::CCharacter () CCharacter::~CCharacter () BITMAP * CCharacter::Wait () Main.cpp #include "Steve.h" #define MODE GFX_AUTODETECT_WINDOWED #define WHITE makecol (255, 255, 255) int main () |
X-G
Member #856
December 2000
|
There are many things wrong here. 1) You never create a CCharacter object, just declare a pointer to one. -- |
Zanmoto
Member #8,665
May 2007
|
1) You never create a CCharacter object, just declare a pointer to one. |
kazzmir
Member #1,786
December 2001
|
1) CCharacter * Player1 = new CCharacter(); 2) CharacterWait = create_bitmap (32, 32); clear_bitmap (CharacterWait); CharacterWait = load_bitmap ("Character_Wait.bmp", NULL); The first two lines are superflous. load_bitmap will create a bitmap for you. All you need is CharacterWait = load_bitmap ("Character_Wait.bmp", NULL); 4) [.code] ... [./code] without the .'s after the [ |
Zanmoto
Member #8,665
May 2007
|
Thank you soo much everyone! This is all valuable programming experience! |
spellcaster
Member #1,493
September 2001
|
May I kindly suggest that you consider reading a C++ introduction? It seems like you might have a lot of potential to improve your knowledge of the basics of this language. -- |
Zanmoto
Member #8,665
May 2007
|
Don't worry, I have read enough C++ stuff (I know that isn't possible), i.e. "Game Programming all in One 1st and 3rd ed.", and a number of online tutorials. It's just practical experience I lack, especially with classes as there aren't many tutorials on game programming with them. |
spellcaster
Member #1,493
September 2001
|
In that case I'd suggest that you consider reading the books and playing around with the examples presented there. I am aware that the examples in these books won't be as exciting as writing a game. But please consider that learning the language and then using that knowledge to create a game will be more fun that starting with the game, getting frustrated and knowing neither the language or how to program games at the end. Another option would be to read the books. Where reading means "reading the book in a way, that you actually remember what was written in it." -- |
|