program HowToCreateASprite; uses SwinGame,sgTypes; procedure Main(); var ball : Sprite; begin OpenGraphicsWindow('Create a Sprite' ,150 ,150 ); ClearScreen(ColorWhite ); LoadBitmapNamed('ball' ,'ball_small.png' ); ball := CreateSprite(BitmapNamed('ball' ) ); SpriteSetX(ball ,60 ); SpriteSetY(ball ,60 ); DrawSprite(ball ); UpdateSprite(ball ); RefreshScreen(); Delay(5000 ); FreeSprite(ball ); ReleaseAllResources(); end; begin Main(); end.
How To Create A Sprite
This beginner level how to explains how to load and draw a sprite to the game window in SwinGame.
Sprites in essence are images. In SwinGame, turning your image into a sprite allows you to apply procedures and functions that can handle collisions, moving, animation and much more. The Sprites API explains these procedures in greater detail.
To create a Sprite you need to declare a variable of a Sprite type. Next you will need to LoadBitmapNamed into the project. Your next step will be to create the sprite, linking the bitmap you loaded with your Sprite variable. The Source code below shows how this performed.
- Try moving your sprite