Sunday, April 22, 2012

Second SDL Program: Bouncing Ball

This is a screen shot of the program

Bouncing Ball Program

The program loads the ball in and bounces it around the screen, as you can see in the screen shot.
I compiled the program with this command:
gcc `sdl-config --cflags --libs`  bouncingball.c

Modified from the tutorial here.

A short note on creating the ball sprite.

I found an image on the Internet of a good looking ball. If you want to own the copyright on the images you work with, just take your own pictures.

The image was huge.  I blurred it to smooth out the colors. Then I did a fill around the outside with FF00FF rgb color.  This is magenta. I put a selection box around the part of the image I wanted to keep and did a trim to selection.  A resize to the finished size and then I had to do another magenta fill around the 4 corners because the resize seemed to change the magenta color just around the edge of the ball.

If you look in the code you will see

SDL_SetColorKey( instance->bitmap, SDL_SRCCOLORKEY, SDL_MapRGB(instance->bitmap->format, 255, 0, 255) );

that is also magenta and anything of that color will not be visible when the sprite is drawn to the screen surface.

No comments:

Post a Comment