Intro to Sprites
Sprites are a widget that let you include sprites in your panel. They are very straightforward.
Constructor
The signature is as follows:
UISprite(_id, _x, _y, _sprite, _width=0, _height=0, _starting_frame=0, _relative_to=UI_DEFAULT_ANCHOR_POINT, _time_source_parent=time_source_global)
where:
idis the string ID.xandyare the offsets with respect to the anchor point. Note that, as directed in the Fundamentals page, your sprites should have its origin point set to top left, to allow for correct positioning in gooey.spriteis the sprite asset to use.widthandheightare optional variables. If set, the sprite will be scaled; if not, the sprite will be drawn at its original size.starting_frameis an optional argument to specify the starting index of the sprite to render (0 if not specified).relative_tois the anchor point, as usual from theUI_RELATIVE_TOenum.time_source_parentis the time source to use in order to animate the sprite. Valid values aretime_source_gameandtime_source_global.
Drawing nine sliced sprites
If you choose a width and height, the sprite will be stretched to match that size. However, if your sprite has nine slice configured, the rendering will use that setting, preventing potential distortions in the sprite rendering. Enable or disable nine slice as needed on the sprites you need to render.
Animation
The gooey system animates each sprite using its own time source. This time source will be set according to the speed configured in the IDE. If the speed is 0, it will not create a time source.
You can set the animation speed at runtime, by calling setAnimationSpeed. The speed can be set in frames or milliseconds, the same than with GameMaker time sources.
You can optionally set an animation length, if you want to limit the animation to a certain number of frames, using setAnimationLength. Additionally, you can set the animation step, i.e., how many frames are skipped in the animation. For example, if your sprite has six frames, and frames 1,3,5 are an animation you want to show (while 2,4,6 are not), you can set the starting frame to 0, then set setAnimationLength to 3 and setAnimationStep to 2, and finally set the speed to run the animation at.
Changing animation parameters
Note that changes will not be visually applied until you restart the animation using animationRestart.
Setting blend and alpha
Remember that all widgets have an image blend and image alpha properties, so you can configure the sprite blend and alpha by using the Widget methods setImageBlend and setImageAlpha.
Example
For this I used ToffeeCraft's pet assets. I imported the sprite sheet of the cat into GameMaker and, after slicing it into individual frames, I had a 64x64 sprite with 12 frames. The objective for this example is to display a sleeping cat and have it wake up on click. The sleeping animation is in frames 9-12. I set up 4 FPS in the inspector, then created the sprite widget and set up the animation length like so:
After doing this, we add a callback to the cat sprite. I use a simple call_later function, to get the cat's sprite widget animation parameters to original, so he can go back to sleep, after 30 frames:
The result is the following. Left click the cat to wake him up (temporarily)...