View Single Post
  #5 (permalink)  
Old 07-07-2008, 02:54 PM
Aereshaa's Avatar   
Aereshaa Aereshaa is offline
Guru
 
Join Date: Apr 2008
Posts: 498
Rep Power: 9
Aereshaa is a jewel in the roughAereshaa is a jewel in the roughAereshaa is a jewel in the roughAereshaa is a jewel in the rough
Default Re: Allegro Game Library

Okay, so, you've got a game, say a clone of space invaders, and you have the game logic all worked out, but wait! You can only draw triangles and squares and lines and circles!
What you need is sprites. Sprites are essentially bitmaps loaded out of a file. Allegro can load sprites from .bmp, .lbm, .tga, and .pcx image files, using the load_bitmap() function, whats syntax is:
Code:
BITMAP * sprite = load_bitmap("whatever.bmp",NULL);
The NULL is a palette, which is only used for 256-color modes.
But remember that all bitmaps must be destroyed using destroy_bitmap() before the end of the program.
To use a sprite, you will need the draw_sprite() function, similar to the blit() function, except that the color FF00FF (bright violet) is treated as transparent. It is used like this:
Code:
draw_sprite(buffer,sprite,x,y);
There are plenty of extra featured versions, such as stretch_sprite()
, which takes a width and height to stretch the sprite to, and rotate_sprite() which takes as an extra argument an angle in fixed point, which you can convert from radians using radtofix_r():
Code:
rotate_sprite(buffer,sprite,x,y,radtofix_r(PI / 3.0)); //rotates 60 degrees

Last edited by Aereshaa; 07-07-2008 at 03:05 PM.
Reply With Quote

Sponsored Links