Jump to content
  • Advertisement
Sign in to follow this  
darenking

Allegro, returning a ref or pointer to a bitmap

This topic is 4729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all! In my game, I am trying to put the screen display stuff in a class called Display. I'm refering to the pointer to the screen buffer, and the variables that store size of screen etc. At the moment they are in the main() function, but I think if I put them in a class then I can give the player the option to change the screen display more than once in the game (while on pause mode). Anyway, the point is, I have to declare the screen buffer inside the class, which I think I can do just fine, with: private: BITMAP* m_Buffer; in the header and then the following constructor: Display::Display() { m_Buffer=create_bitmap(WIDTH, HEIGHT); } I know how to write a method that draws this buffer to the screen, that's all fine, but what about when another one of my classes wants to draw to the buffer? Two questions: 1. Is it structurally better for my classes that hold the image bitmaps (monsters, background blocks etc) to send their bitmap pointer/reference to this Display class along with coordinates, *OR* is it better to have them draw themselves, by asking the Display class for a reference or pointer to the screen buffer? 2. If I go for the second option, how do I return a pointer or reference to the m_Buffer private member bitmap so that the calling function can access it?

Share this post


Link to post
Share on other sites
Advertisement
Answering just the "how to" portion:


class BadGuy {
private:
BITMAP *canvas;

public:
BadGuy () {
canvas = create_bitmap(64,64);
}
BITMAP *getCanvas( return canvas; );
};


BadGuy baddie;
blit(baddie.getCanvas(), screen, ... );




By the way, make sure that the constructor gets called after you have already called set_gfx_mode(). If your class gets created before the screen has been set, the bitmap will be invalid.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!