|
Pointing to a Bitmap |
BrunoProg64
Member #6,831
January 2006
|
I have a problem. I make a class that use two BITMAPS objects in private ambit. But also I want to use the same objects in the public ambit. To your understanding, the code:
Basicaly I want the pointers fbackg y fmaskedbackg, pointing to background and maskedbackground respectively. I need your help. Thanks for your time. (I include the declaration and the implementation of the class as an attachments.) http://www.allegro.cc/files/attachment/590609 -> fbackground.h A complete newbie who wants to learn something. |
Kris Asick
Member #1,424
July 2001
|
There are a variety of solutions. The simplest would be to make a public function you could call that would assign the pointers. Another, more advanced method, would be to overload the = operator so that when you use it when loading a bitmap, the bitmap pointer is assigned to both variables. Though quite frankly, why do you need to keep track of both a private and public copy of the same pointer? It would be much simpler just to have the public bitmap pointers instead of both. Remember that when you create a bitmap, you're still assigning a pointer to it, not the data itself. For example, this is legal: BITMAP *bitmap_one, *bitmap_two; bitmap_one = create_bitmap(64,64); bitmap_two = bitmap_one; bitmap_one = NULL; destroy_bitmap(bitmap_two);
--- Kris Asick (Gemini) --- Kris Asick (Gemini) |
Simon Parzer
Member #3,330
March 2003
|
jamal
Member #3,326
March 2003
|
void fbackground::explodeterrain(int x, int y, int radius) { //... //Suena un .wav (requiere que la opción de sonido esté activa) explode = load_sample("explode.wav"); // this line play_sample(explode, 255, 128, 1000, 0); }
you shouldn't use load_sample each time you want to play a sample.
Quote: Basicaly I want the pointers fbackg y fmaskedbackg, pointing to background and maskedbackground respectively.
I can't see the reason why you want to do this, but you have to do it after int fbackground::loadbackground(char* filename) { background=load_bitmap(filename,NULL); if (!background) { return -1; //error } else { fbackg=background; return 0; //éxito } }
|
BrunoProg64
Member #6,831
January 2006
|
Thanks for your sugestions. Really I going to change to a public variable instead of pointing twice. Your code works! A complete newbie who wants to learn something. |
|