Learn More

Friday, August 26, 2011

Adjusting Color

Yesterday we discussed the basics of using the keyboard to control the game. We want you to repeat. For the future we will discuss further. However, before that we want to discuss the most important of it all. That set the coloring. This is the key of the beautiful appearance of our game. Because without it, we will only produce a game with a bad mix of colors. Consider the following figure

non fix color game

Did you see? There are still white color around tank and bazooka. We don't want it happen. Of course we can fix it, so we can set white color around those disappears from our game. There are two way to fix it, first we using SDL_DisplayFormatAlpha (not using SDL_DisplayFormat), second if we still using SDL_DisplayFormat then we must combine it with SDL_MapRGB and SDL_SetColorKey. Actually, we love to using DisplayFormatAlpha. But in here, we will give two way to do that. So you have more reference for better game. We hope.

Fix For Loading Image Function

Because on our post we just optimized it without mix the color to get the best performance. Then we must fix load_image function. Like we told above, there are two way to do that, see the example script below

1. First script

2. Second script

What you should to is SDL_DisplayFormatAlpha takes a surface and copies it to a new surface of the pixel format and colors of the video framebuffer plus an alpha channel, suitable for fast blitting onto the display surface. It calls SDL_ConvertSurface

If you want to take advantage of hardware colorkey or alpha blit acceleration, you should set the colorkey and alpha value before calling this function.

This function can be used to convert a colourkey to an alpha channel, if the SDL_SRCCOLORKEY flag is set on the surface. The generated surface will then be transparent (alpha=0) where the pixels match the colourkey, and opaque (alpha=255) elsewhere.

Fix Int Main

Remind again, please read our explanation about how to choose a picture from an image on basic using keyboard. Because we will show tank and bazooka from one image. The name of that file is sprites.png. After your read and try with several input data of drawfiles function, you will more understand.

Next Step

Basically it is still with our tutorial before, please run your project. You can download the script for SDL_DisplayFormatAlpha and / or without SDL_DisplayFormatAlpha. Ok, finish. If you follow this tutorial carefully then the result will like the picture below. Ok, see you for the next tutorials.

fix color of game

Post a Comment