Archived

This topic is now archived and is closed to further replies.

Tutorial 3: Why the struct?

This topic is 5011 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

On tutorial 3 why is there a struct for CSpriteFrame and not a class? I mean if you put a class in the program instead of the struct would it make any difference. Also if anyone could explain clearBG and updateBG it would be a great help. Please help.

Share this post


Link to post
Share on other sites
Generally, a struct is used when there is no need for member functions or to maintain compatability with regular C code.

The Code on the Cob articles discuss this to some extent, with Chris (the author) believing that Classes are often used by people thinking that just by using them, they get real OOP code.

Share this post


Link to post
Share on other sites
Thx I understand now also there are two more things I am confused about. Why would you want to make anything transparent and when you do how come you only make red transparent and not the rest?

if(r >= 0) SDL_SetColorKey(temp, SDL_SRCCOLORKEY,
SDL_MapRGB(temp->format, r, g, b));

Also what exactly does DisplayFormat do? I mean is it just copying the image or what?

[edited by - CrazyMeat on March 26, 2004 6:34:03 PM]

Share this post


Link to post
Share on other sites
the standard SIMPLE way to draw with transparency, is to use one exact color be your official TRANSPARENT COLOR ... and then when you blit the image, you tell the renderer what color is transparent ... and what it does is, draw every pixel that is not that color, and not draw the pixels that are ...

THINK GREEN SCREEN HERE ...

if you have an image that has a person in it, but a certain color (say bright green) is surrounding that person ... then you render the image with bright green set to transparent ... and you get ONLY THE PERSON drawn onto the scene .. the green backgroun is not drawn ... hence the idea of TRANSPARENT colors ...

this is different than translucency / opacity and alpha blending ...

Share this post


Link to post
Share on other sites
If you are overlaying an image onto the screen as a sprite you will need a transparent colour so that the unneccessary portions of the sprite are removed. Otherwise you''d have a huge block of colour running over your background.

The red is picked as being transparent because it''s not needed. Generally, you''d use a ''shocking'' colour for your transparency which will allow you to use base colours such as red normally. You''ve heard the film term ''blue screening'' before, right? This is where anything blue is overlayed with a video layer, effectively making things blue ''look'' transparent. It''s basically a similar process.

Likewise in 3d textures, it''s sometimes useful to allow things a measure of transparency.

DisplayFormat is a description of the display format, mainly Size of the display rectangle and the colour depth.

Share this post


Link to post
Share on other sites