Solarus quests
1.6
Quest maker's reference
|
A sprite is an animated image. It is managed by an animation set. The animation set defines which animations are available and describes, for each animation, a sequence of images in each direction.
A sprite has the following properties:
"walking"
or "hurt"
),The animation set of a sprite is composed of one or several PNG images that store all the frames, and a data file that describes how frames are organized in the PNG images. The data file also indicates the delay to make between frames when animating them and other properties like whether the animation should loop. See the sprites syntax for more information about the format of sprites.
We describe here the Lua API that you can use to show sprites during your game or your menus.
Creates a sprite.
animation_set_id
(string): Name of the animation set to use. This name must correspond to a valid sprite sheet data file in the sprites
directory (without its extension).nil
if the sprite data file could not be loaded.Sprites are particular drawable objects. Therefore, they inherit all methods from the type drawable.
See Methods of all drawable types to know these methods.
The following methods are specific to sprites.
Returns the name of the animation set used by this sprite.
sprites
directory (without its extension).Returns whether the specified animation exists on a sprite.
animation_name
(string): Name of the animation to check.true
if the sprite animation set contains an animation with this name.Returns the name of the current animation of this sprite.
Sets the current animation of this sprite.
animation_name
(string): Name of the animation to set. This animation must exist in the animation set.next_action
(function or string, optional): What to do when the animation finishes. This parameter only has an effect if the animation finishes, that is, if it does not loop. If you pass a function, this function will be called when the animation finishes. If you pass a string, this should be the name of an animation of the sprite, and this animation will automatically be played next. No value means no action after the animation finishes: in this case, the sprite stops being displayed.Stops playing the current animation of this sprite.
The sprite stops being displayed, like when the last frame finishes.
Returns whether the current animation is being played.
true
if the current animation is playing, false
if it is finished or was stopped.Returns the current direction of this sprite.
0
).Sets the current direction of this sprite.
direction
(number): The direction to set (the first one is 0
). This direction must exist in the current animation.Returns the number of direction of an animation of this sprite.
animation_name
(string, optional): Name of an animation of the sprite. This animation must exist in the animation set. No value means the current animation.Returns the index of the current frame of this sprite.
0
).Sets the current frame of this sprite.
frame
(number): The frame to set (the first one is 0
). This frame must exist in the current direction.Returns the number of frames of this sprites in an animation and direction.
animation_name
(string, optional): Name of an animation of the sprite. This animation must exist in the animation set. No value means the current animation.direction
(number, optional): A direction of this animation, between 0
and sprite:get_num_directions(animation_name) - 1
. No value means the current direction.Returns the delay between two frames of this sprite in an animation.
The delay of the current animation may be overriden by set_frame_delay().
animation_name
(string, optional): Name of an animation of the sprite. This animation must exist in the animation set. No value means the current animation.nil
means infinite and it is only allowed for single-frame animations.Changes the delay between two frames of this sprite in the current animation.
Use this function if you want to override the normal delay (the one defined in the sprite data file).
delay
(number): The new delay in milliseconds. nil
means infinite and is only allowed for single-frame animations.Returns the frame size of this sprite in an animation and direction.
animation_name
(string, optional): Name of an animation of the sprite. This animation must exist in the animation set. No value means the current animation.direction
(number, optional): A direction of this animation, between 0
and sprite:get_num_directions(animation_name) - 1
.Returns the coordinates of the origin point of this sprite in an animation and direction, relative to the upper left corner of a frame.
The origin is the point of synchronization for sprites that have several animations or directions of different sizes, and for entity sprites that are larger than the entity itself.
See entity:get_origin() for more details.
In a given animation and direction of a sprite, the origin point is the same for all frames.
animation_name
(string, optional): Name of an animation of the sprite. This animation must exist in the animation set. No value means the current animation.direction
(number, optional): A direction of this animation, between 0
and sprite:get_num_directions(animation_name) - 1
.Returns the coordinates of a frame in its source image.
animation_name
(string, optional): Name of an animation of the sprite. This animation must exist in the animation set. No value means the current animation.direction
(number, optional): A direction of this animation, between 0
and sprite:get_num_directions(animation_name) - 1
. No value means the current direction.frame
(number, optional): A frame number. No value means the current frame.Returns whether this sprite is paused.
true
if this sprite is paused.Pauses or resumes the animation of this sprite.
paused
(boolean, optional): true
to pause the sprite, false
to unpause it. No value means true
.Returns whether the animation should continue even when the game is suspended.
This setting only has an effect when a game is running. The default value is false
.
true
to continue the animation even when the game is suspended.Sets whether the animation should continue even when the game is suspended.
ignore
(boolean, optional): true
to continue the animation even when the game is suspended. No value means true
.Synchronizes the frames of this sprite with the frames of a reference sprite. The synchronization will be performed whenever both animation names match. The current sprite will no longer apply its normal frame delay: instead, it will now always set its current frame to the current frame of its reference sprite.
reference_sprite
(sprite, optional): The reference sprite. nil
means stopping any previous synchronization.Events are callback methods automatically called by the engine if you define them.
The following events are specific to sprites.
Called when the current animation of this sprite is finished.
If the animation loops, this function is never called. Unless you start another animation, the sprite is no longer shown.
animation
(string): Name of the animation that has just finished.Called whenever the animation of this sprite has changed.
animation
(string): Name of the new animation.Called whenever the direction of this sprite has changed.
animation
(string): Name of the current animation.direction
(number): The new current direction (the first one is 0
).Called whenever the frame of this sprite has changed.
animation
(string): Name of the current animation.frame
(number): The new current frame (the first one is 0
).