|
This thread is locked; no one can reply to it. |
1
2
|
c++ design... |
Don Freeman
Member #5,110
October 2004
|
What I mean is that you will only have one instance and only one pointer to this image and this will make your code faster and use less memory since you don't need 50 pointers to the same image! Just use one pointer for the image you need. I did notice I didn't show you how to use the static data from the class so here it goes: // [Global scope:] // [Function scope:] Hope that helps!:) -- |
23yrold3yrold
Member #1,134
March 2001
|
Your code, Mr. Freeman ...
Okay, I create 50 enemies, call LoadImage() so they all have the image, one enemy dies ... and I'm screwed. I also like the idea of seperate pointers for enemies so I could, say, create 4 slightly different images/animations for an enemy for variety's sake, so it doesn't just look like the same boring enemy clones running around. Or you could use the same enemy class with different level-specific graphics (tons of platformers and shooters do this). -- |
ReyBrujo
Moderator
January 2001
|
You cannot delete a bitmap I prefer the idea of a singleton holding all the images, and the mobiles requesting pointer to a const BITMAP for them to blit. -- |
23yrold3yrold
Member #1,134
March 2001
|
Quote: You cannot delete a bitmap And the check for NULL before deleting is a waste and the constructor code should be in the initialization list, etc. Just talking about the topic here. -- |
Don Freeman
Member #5,110
October 2004
|
To 23yrold3yrold: If you read his openning question on this thread... I KNOW that if you did what you say you would not be able to use differant images, but he said that he only has one!;) Also, checking to see if the pointer is NULL or not will save a run time error if you delete a pointer twice...it is also good coding practice!:P I DID do a no no though:(, I didn't write destroy_bitmap(pImage);) -- |
23yrold3yrold
Member #1,134
March 2001
|
Quote: Also, checking to see if the pointer is NULL or not will save a run time error if you delete a pointer twice...it is also good coding practice! No, it is a bad coding practice because it wastes time. Deleting a NULL pointer is guarenteed to do nothing. No error, no crash. Quote: I KNOW that if you did what you say you would not be able to use differant images, but he said that he only has one!;) That's fine, but it still doesn't change the fact that when one dies, the image is lost. A better idea might be to call the initialization function before a level, and another function to destroy the bitmap after. And he may change his mind later. It's not like pointers are memory hogs ... -- |
Don Freeman
Member #5,110
October 2004
|
I retract my statements...I messed up:D You could use ref counts such as: class Object And yes, having just the pointer around harms no one, but when he's got 50 or so pointing to and having loaded all of the same image it is a huge waste and unneccassary when all you need is one BITMAP loaded!:o -- |
23yrold3yrold
Member #1,134
March 2001
|
Quote: it is a huge waste 50 bytes? -- |
Don Freeman
Member #5,110
October 2004
|
I'm talking about when he has all 50 loaded using load_bitmap::)...not the 50 pointers...even though if you could use one instead of 50...well that's still another improvement...I KNOW NOT MUCH:P -- |
23yrold3yrold
Member #1,134
March 2001
|
Quote: I'm talking about when he has all 50 loaded using load_bitmap Nobody suggested he do that, though ... -- |
|
1
2
|