MoveObj (CMS)
From The Official Visionaire Studio: Adventure Game Engine Wiki
Name | Type | By |
---|---|---|
moveObj("obj", x, y, duration, easing) | Definition | AFRLme |
This small function allows you to move an object immediately from one position to another (absolute positioning); or over x amount of time with optional easing. (positioning is based on top left pixel belonging to the linked image or animation).
Instructions
1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. Usage Example #1: move object immediately from current position to 100, 100.
moveObj("object_name", 100, 100)
2b. Usage Example #2: move object over 2000ms from current position to 100, 100 with easeBounceOut easing.
moveObj("object_name", 100, 100, 2000, easeBounceOut)
Main Script
function moveObj(obj, x, y, duration, easing, pos)
duration = duration or 0 -- fallback in case duration equals nil
easing = easing or easeLinearInOut -- fallback in case easing equals nil
obj = game.CurrentScene.Objects[obj] -- store object
-- + --
if obj.Animation:isEmpty() then -- check if animation isn't linked to scene object
pos = obj.Sprite.Sprite:getPosition() -- store object sprite position (top left pixel)
else
pos = ActiveAnimations[obj.Animation:getName()].CurrentPosition -- store linked animation position (top left pixel)
end
-- + --
obj:to(duration, { Offset = {x = x - pos.x, y = y - pos.y} }, easing) -- update object position
end
Syntax Breakdown
Name | Type | Description |
---|---|---|
obj | "string" | This should be a "string" value containing the name of the object you want to move. |
x | integer | This should contain a number value consisting of the x coordinate you want to move the object to. |
y | integer | This should contain a number value consisting of the y coordinate you want to move the object to. |
duration | integer | This should be a an integer value of the amount of time in milliseconds it should take the object to get from current position to the target position. |
easing | integer | This should contain a number value, or the variable name of the easing type that you want to use. Here is a list of available easing options. |