Module ncine.animated_sprite
The table containing animated sprite related functions.
Inherits from ncine.sprite.
Functions
ncine.animated_sprite.new (parent, texture, x, y) | Constructs an animated sprite object with a parent scene node, a texture, and position components. |
ncine.animated_sprite.new (parent, texture, pos) | Constructs an animated sprite object with a parent scene node, a texture, and a position vector. |
ncine.animated_sprite.clone (sprite) | Constructs a new animated sprite object as a clone of the specified one. |
ncine.animated_sprite.delete (sprite) | Destroys an animated sprite object and releases its memory |
ncine.animated_sprite.is_paused (sprite) | Returns true if the current animation is paused |
ncine.animated_sprite.set_paused (sprite, paused) | Sets the pause state for the animation |
ncine.animated_sprite.add_animation (sprite, anim) | Adds a new animation |
ncine.animated_sprite.clear_animations (sprite) | Deletes all animations |
ncine.animated_sprite.num_animations (sprite) | Returns the number of animations |
ncine.animated_sprite.get_animation_index (sprite) | Returns the current animation index |
ncine.animated_sprite.set_animation_index (sprite, index) | Sets the current animation index |
ncine.animated_sprite.num_frames (sprite) | Returns the number of frames in current animation |
ncine.animated_sprite.get_frame (sprite) | Returns the frame number in current animation |
ncine.animated_sprite.set_frame (sprite, frame) | Sets current animation to a specified frame number |
Tables
animatedspriteObj | The light user data of an animated sprite object. |
rect_animation Functions
ncine.loop_mode | Loop state (enumeration) |
ncine.rewind_mode | Rewind modes (enumeration) |
ncine.rect_animation | A rectangle based animation data table |
Functions
- ncine.animated_sprite.new (parent, texture, x, y)
-
Constructs an animated sprite object with a parent scene node, a texture, and position components.
Don’t forget to call ncine.animated_sprite.delete when you are done with it!
Parameters:
- parent ncine.scenenode.scenenodeObj or nil The parent scenenode
- texture ncine.texture.textureObj or nil The texture object
- x number The X component of the position
- y number The Y component of the position
Returns:
-
animatedspriteObj
A new animated sprite object
- ncine.animated_sprite.new (parent, texture, pos)
-
Constructs an animated sprite object with a parent scene node, a texture, and a position vector.
Don’t forget to call ncine.animated_sprite.delete when you are done with it!
Parameters:
- parent ncine.scenenode.scenenodeObj or nil The parent scenenode
- texture ncine.texture.textureObj or nil The texture object
- pos ncine.vec2 The position vector
Returns:
-
animatedspriteObj
A new animated sprite object
- ncine.animated_sprite.clone (sprite)
-
Constructs a new animated sprite object as a clone of the specified one.
Don’t forget to call ncine.animated_sprite.delete when you are done with it!
Parameters:
- sprite animatedspriteObj The sprite object to be cloned
Returns:
-
animatedspriteObj
The cloned animated sprite object
- ncine.animated_sprite.delete (sprite)
-
Destroys an animated sprite object and releases its memory
Parameters:
- sprite animatedspriteObj The animated sprite object to be destroyed
- ncine.animated_sprite.is_paused (sprite)
-
Returns
true
if the current animation is pausedParameters:
- sprite animatedspriteObj
Returns:
-
boolean
- ncine.animated_sprite.set_paused (sprite, paused)
-
Sets the pause state for the animation
Parameters:
- sprite animatedspriteObj
- paused boolean
- ncine.animated_sprite.add_animation (sprite, anim)
-
Adds a new animation An example of a valid animation table is the following:
local animation = { frame_duration = 0.5, -- half a second loop_mode = nc.loop_mode.ENABLED, rewind_mode = nc.rewind_mode.FROM_START, rect_size = { x = 32, y = 32 }, source_rect = { x = 0, y = 0, w = 96, h = 48 }, num_rectangles_to_skip = 0, -- default is 0 if the field is not specified padding = { x = 0, y = 0 }, -- default is {x = 0, y = 0} if the field is not specified }
Parameters:
- sprite animatedspriteObj
- anim ncine.rect_animation
- ncine.animated_sprite.clear_animations (sprite)
-
Deletes all animations
Parameters:
- sprite animatedspriteObj
- ncine.animated_sprite.num_animations (sprite)
-
Returns the number of animations
Parameters:
- sprite animatedspriteObj
Returns:
-
integer
- ncine.animated_sprite.get_animation_index (sprite)
-
Returns the current animation index
Parameters:
- sprite animatedspriteObj
Returns:
-
integer
- ncine.animated_sprite.set_animation_index (sprite, index)
-
Sets the current animation index
Parameters:
- sprite animatedspriteObj
- index integer
- ncine.animated_sprite.num_frames (sprite)
-
Returns the number of frames in current animation
Parameters:
- sprite animatedspriteObj
Returns:
-
integer
- ncine.animated_sprite.get_frame (sprite)
-
Returns the frame number in current animation
Parameters:
- sprite animatedspriteObj
Returns:
-
integer
- ncine.animated_sprite.set_frame (sprite, frame)
-
Sets current animation to a specified frame number
Parameters:
- sprite animatedspriteObj
- frame integer
Tables
- animatedspriteObj
-
The light user data of an animated sprite object.
Inherits from ncine.sprite.spriteObj.
rect_animation Functions
- ncine.loop_mode
-
Loop state (enumeration)
Fields:
- DISABLED
- ENABLED
- ncine.rewind_mode
-
Rewind modes (enumeration)
Fields:
- FROM_START When the animation reaches the last frame it begins again from start
- BACKWARD When the animation reaches the last frame it goes backward
- ncine.rect_animation
-
A rectangle based animation data table
Fields:
- loop (ncine.loop_mode)
- rewind (ncine.rewind_mode)
- rect_size (ncine.vec2)
- source_rect (ncine.rect)
- padding (ncine.vec2) Optional field, default is { x = 0, y = 0 }
- frame_duration number Frame duration in seconds
- num_rectangles_to_skip integer Optional field, default is 0