Smoovement.lua

From Moondust Wiki
Revision as of 00:50, 30 April 2016 by Spinda (talk | contribs)
Jump to navigation Jump to search

Smoovement is an API that introduces sprite objects and ways to transform them as well as parent-children relationships.

Installation

Just download this and extract it. Then, copy the file into your level's graphics folder. Rinkas;Tale, an example level, is included, too.


Setup

To enable the smoovement library for a specific level, add this line to lunadll.lua:

local smoovement = API.load ("smoovement");

This will load the smoovement API.


Documentation

Values

These are variables you can access.

world sprite The sprite object used for referencing everything. Any transformations applied to this sprite will get applied to every sprite.

Sprite

Values

Sprite.img The LuaImageResource that the sprite is currently displaying
Sprite.x The x translation relative to its parent
Sprite.y The y translation relative to its parent
Sprite.rotation The current rotation of the sprite relative to its parent in degrees
Sprite.pivotX The x coordinate of the pivot point, the point that's used as the center for scaling and rotation, where 0 represents the leftmost side of the sprite and 1 the rightmost
Sprite.pivotY The y coordinate of the pivot point, the point that's used as the center for scaling and rotation, where 0 represents the top of the sprite and 1 the bottom
Sprite.scaleX The value by which the sprite is scaled horizontally
Sprite.scaleX The value by which the sprite is scaled vartically
Sprite.visible boolean containing whether the sprite is visible
Sprite.hasParent boolean containing whether the sprite has a parent
Sprite.parent Parent sprite
Sprite.children table of children
Sprite.hasAnimation boolean containing whether the sprite is animated
Sprite.dTime Number of frames between animations
Sprite.counter A counter that increases from 0 to Sprite.dTime - 1 and is used to keep track of animation
Sprite.frame The index of the frame that the sprite is currently on
Sprite.frames table of LuaImageResource, with each one representing one frame of animation
Sprite.priority Priority with which the sprite is drawn. See LunaLua Render Priority
Sprite.transform The transform of the sprite; only used for rendering
Sprite.deleted boolean containing whether the sprite, as well as its children, are to be deleted on the next frame

Functions

Sprite:moveTo x y
Moves the sprite to the specified coordinates nil number

The new x coordinate

number

The new y coordinate

Sprite:setPivot x y
Sets the pivot point to the specified coordinates nil number

The new x coordinate of the pivot point

number

The new y coordinate of the pivot point

Sprite:setScale x y
Sets the scale of the sprite nil number

The new x scale

number

The new y scale

Sprite:setParent sprite
Sets a new parent sprite nil Sprite

The parent sprite

Sprite:removeParent
Removes the parent sprite nil
Sprite:setAnimation frames dTime
Sets the sprite's animation nil table of LuaImageResource

The animation frames

number

The amount of frames between frames of animation

Sprite:setSprite sprite
Sets the image of the sprite nil LuaImageResource

The new sprite