SpriteTools 2.2
Ended up borrowing some code from the original SpriteTools to save time here.
Make sure you read the ReadME before asking questions. Many of them are answered there.
How to Use
Extract the Source listed below to an empty folder, then run the command make install
to install the library and all of its dependencies. You may need sudo
privileges to do so on Linux and macOS.
Attached is an example.2.2.zip
file as an example of how to use the library.
New to SpriteTools and/or programming? Check out the Tutorial on the Wiki. It's designed for beginners so even if you have no experience, you should get by fine.
Showcase Video
New Features
Compiling
It's finally here! You can now compile and install the library to your development environment. No more copy-pasting .c and .h files.
Easy-Install Dependencies
The Makefile can now download and install all needed dependencies on its own! That means you only need to worry about downloading Spritetools to get everything you need - no more repository searching.
Cameras
-
You can create and free cameras using
ST_CameraCreate(double x, double y)
(returns a pointer to a camera) andST_CameraFree(st_camera *cam)
-
You can use the following functions to modify a camera by the given values:
ST_CameraMoveBy(st_camera *cam, double x, double y)
,ST_CameraRotateBy(st_camera *cam, float rot)
,ST_CameraZoomBy(st_camera *cam, float zoom)
,ST_CameraColorChange(st_camera *cam, u8 r, u8 g, u8 b, u8 a)
-
You can use the following functions to set a camera's settings by the given values:
ST_CameraMoveTo(st_camera *cam, double x, double y)
,ST_CameraRotateSet(st_camera *cam, float rot)
,ST_CameraZoomSet(st_camera *cam, float zoom)
,ST_CameraColorSet(st_camera *cam, u8 r, u8 g, u8 b, u8 a)
-
You can render with a camera using
ST_RenderEntityCamera(st_entity *entity, st_camera *cam)
. -
Alternatively, you can use
ST_RenderEntityCameraNoSpriteRot(st_entity *entity, st_camera *cam)
render without rotating sprites, just their positions.
Entity Following Cameras
-
You can tell a camera to follow an entity with
ST_CameraSetFollowEntity(st_camera *cam, st_entity *ent)
-
Clear the camera's followed entity with
ST_CameraClearFollowEntity(st_camera *cam)
-
You can set and modify a camera's offset from the entity it's following with
ST_CameraMoveFollowOffsetBy(st_camera *cam, double x, double y)
andST_CameraMoveFollowOffsetTo(st_camera *cam, double x, double y)
respectively. -
Use
ST_CameraMoveToFollow(st_camera *cam)
to set a camera's position, rotation, and scale to match it's settings relative to the entity it's following. Has no effect if the camera is not following an entity. -
Cameras now have the following "follow-flags":
Flag | Description |
---|---|
CFF_ROTATE_WITH_ENTITY | Sets the camera's rotation to the followed entity's rotation |
CFF_OFFSET_WITH_ROTATION | Modifies the camera's offset by rotating it around the entity by thier rotation value |
CFF_INVERT_SCALE_WITH_ENTITY | Sets the camera's scale to be the inverse of the followed entity's scale |
CFF_OFFSET_WITH_SCALE | Modifies the camera's offset by scaling it by the thier scale value |
CFF_ALL | For use when setting or toggling all flags |
-
ST_CameraSetFollowFlag(st_camera *cam, CAMERA_FOLLOW_FLAGS flag, bool state)
will set a camera's follow-flag totrue
orfalse
based on thestate
given. -
ST_CameraSetToggleFlag(st_camera *cam, CAMERA_FOLLOW_FLAGS flag, bool state)
will toggle a camera's flag on and off. -
You can use
ST_CameraCheckFollowFlag(st_camera *cam, CAMERA_FOLLOW_FLAGS flag)
to test if a camera's follow-flag is on.
Main Camera
It can sometimes make code shorter if there is a "Main Camera" in use. An example would be rendering from multiple cameras depending on the buttons being pressed. You can make give every option their own render function which may be more difficult to debug or harder to read, or you can use one "main" camera to render with all the time and have a few if
statements switch which camera is the "main" one.
-
ST_MainCameraSet(st_camera *cam)
will set the Main Camera to the given camera. -
ST_MainCameraClear()
will clear the Main Camera. -
ST_MainCameraGet()
will return the Main Camera.
Added sfillib Support
In response to #4.
If you have sfillib installed (it will be if you install SpriteTools using the provided Makefile), you can now use the following functions as you would in sfillib. They all return a st_spritesheet *
.
-
ST_SpritesheetCreateSpritesheetPNG(const void *buffer)
-
ST_SpritesheetCreateSpritesheetBMP(const void *buffer)
-
ST_SpritesheetCreateSpritesheetJPEG(const void *buffer, unsigned long buffer_size)