Smoovement.lua
| This is the archived page of the old LunaLua documentation The rest of LunaLua related articles in this wiki contain a lot of outdated documentation preserved for historical purposes and may be used with legacy versions of the LunaLua.
Please visit the SMBX2 Documentation Page to access the latest documentation for the LunaLua scripting system of the SMBX2 Project. Adding LunaLua contents into this Wiki is not advised. |
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.
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. |
|---|---|---|
| customDraw | boolean | If this is set to true, sprites will not be drawn in smoovement.lua but can instead be drawn at will through smoovement.draw(). |
| customTick | boolean | If this is set to true, there won't be any calculations in smoovement.lua but they can be called through smoovement.tick(). |
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 vertically. |
| Sprite.visible | boolean containing whether the sprite is visible. |
| Sprite.usesSceneCoords | boolean containing whether the will be drawn to the scene instead of to the screen. False by default. |
| Sprite.hasParent | boolean containing whether the sprite has a parent. Don't edit this manually. |
| Sprite.parent | Parent sprite. Don't edit this manually. |
| Sprite.children | table of children. Don't edit this manually. |
| 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. |
External Use Functions
These are functions you will need to use the library.
| createSprite | properties | ||
|---|---|---|---|
| Creates a Sprite object. | Sprite | table
The properties of the sprite. | |
| draw | |||
| Executes the drawing operations. | nil | ||
| tick | |||
| Executes the calculating operations. | nil | ||
| translateM | x | y | |
| Creates a transformation matrix from the x and y coordinates. | matrix3 | number
The x coordinate. |
number
The y coordinate. |
| rotateM | sin | cos | |
| Creates a rotation matrix from the sin and cosine of an angle. | matrix3 | number
The sin. |
number
The cosine. |
| scaleM | x | y | |
| Creates a scaling matrix from the amount of stretching of the x and y axis. | matrix3 | number
How much the x-axis is stretched. |
number
How much the y-axis is stretched. |
| vectorTransToXY | vector | trans | |
| Takes a vector2 and a transformation matrix and outputs the new x and y coordinates. | number, number | vector2
The vector2 to transform. |
matrix3
The transformation matrix. |