Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2002 Bolton Institute The AWSprite Library Andrew Williams

Similar presentations


Presentation on theme: "Copyright © 2002 Bolton Institute The AWSprite Library Andrew Williams"— Presentation transcript:

1 Copyright © 2002 Bolton Institute The AWSprite Library Andrew Williams A.Williams@bolton.ac.uk http://www.bolton.ac.uk/staff/adw1

2 Copyright © 2002 Bolton Institute Why bother? There are lots of sprite libraries available –SDLSprite Seems to have bugs –Kyra Couldn't make it build on PlayStation dev kits Kyra is the Rolls-Royce of SDL sprite libraries –It does everything, and is beautifully written It is very complex, far more than we need

3 Copyright © 2002 Bolton Institute AWSprite - Features Simple to use Windows bitmap format (.bmp) compatible World co-ordinate system –Mapped onto screen space Autonomous sprite movement –Time-based Simple transparent colour selection

4 Copyright © 2002 Bolton Institute AWSprite - Features Autonomous animation –Time-based Floating-point world coordinates –Translated to int for display Floating-point velocity in x and y directions Floating-point acceleration in x and y directions –Independent acceleration timers

5 Copyright © 2002 Bolton Institute AWSprite – NYI Features Not yet implemented, as of 8 th October 2004: –Alpha channel –Rotation (Stupid f&*!$?!* roto-zoom functionality) –Documentation (“Use the source, Luke”)

6 Copyright © 2002 Bolton Institute First Things First Much of AWSprite's functionality depends on your already having done two things: –Initialized SDL: SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); –Set the video mode (all one line of course): SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);

7 Copyright © 2002 Bolton Institute AWSprite Loading and formatting a single sprite: AWSprite *football; football = new AWSprite(“ball.bmp”, 1) –First parameter is the name of the.bmp file –Second parameter is number of animation frames The ball here doesn't have any animation

8 Copyright © 2002 Bolton Institute AWSprite Loading and formatting an animated sprite: AWSprite *fighter; fighter = new AWSprite(“fighter.bmp”, 6) –You don't need to specify how wide the frames are The program divides the total width by the number of frames Frames must be placed side-by-side:

9 Copyright © 2002 Bolton Institute Setting Transparency Simplified by hiding some of the complexity: football->set_transparent_colour(0, 0, 0); Parameters are: 1.Red 2.Green 3.Blue (0,0,0) = BLACK (255, 255, 255) = WHITE

10 Copyright © 2002 Bolton Institute Sprite Movement Done in three stages: –Tell the sprite how fast (x, y): football->set_velocities(1.0, 0.0); –Tell the sprite how often (milliseconds) football->set_auto_move(10); –Tell the sprite to actually move (this is done in the game loop): football->update_everything();

11 Copyright © 2002 Bolton Institute Sprite Movement - Velocity Tell the sprite how fast (x, y): football->set_velocities(1.0, 0.0); –Units are pixels Remember, in world coordinate space, which may not be the same as screen space –This member function does not actually move the sprite: You can move it manually with the move() member function Or you an use the automove feature (next slide)

12 Copyright © 2002 Bolton Institute Sprite Movement - auto_move You can tell the sprite to move automatically at its current velocity using: set_auto_move(interval); The interval is the number of milliseconds to wait before moving the sprite based on its velocity –Note that this does not move the sprite!! –It just sets up automatic movement

13 Copyright © 2002 Bolton Institute Sprite Animation Animation is also controlled by a timer: set_auto_animate(m); m is the number of milliseconds you want to wait before flipping to the next frame As with set_auto_move(..), this does not animate the sprite –That is done elsewhere –All this does is to tell your sprite how fast you want the animation to go

14 Copyright © 2002 Bolton Institute Sprite Acceleration Tell the sprite how fast to accelerate by using: set_accelerations(0.1, 0.0); –Units are pixels –Units are added to velX and velY to achieve acceleration We can set up automatic acceleration by doing set_auto_accelerate(m); Where m is the number of milliseconds to wait –Again, acceleration is not applied by this function

15 Copyright © 2002 Bolton Institute Displaying the Sprite If you're using auto-move, auto-animate or auto-acceleration, you should use football->update_everything(); If you are controlling the movement of the sprite yourself, just use: football->map_world_to_screen(); football->draw(); This is done at the bottom of the game loop


Download ppt "Copyright © 2002 Bolton Institute The AWSprite Library Andrew Williams"

Similar presentations


Ads by Google