MCPcopy Create free account
hub / github.com/defold/defold / Script_Animate

Function Script_Animate

engine/gameobject/src/gameobject/gameobject_script.cpp:1614–1733  ·  view source on GitHub ↗

animates a named property of the specified game object or component * * This is only supported for numerical properties. If the node property is already being * animated, that animation will be canceled and replaced by the new one. * * If a `complete_function` (lua function) is specified, that function will be called when the animation has completed. * By starting a n

Source from the content-addressed store, hash-verified

1612 * ```
1613 */
1614 int Script_Animate(lua_State* L)
1615 {
1616 int top = lua_gettop(L);
1617 (void)top;
1618
1619 DM_HASH_REVERSE_MEM(hash_ctx, 256);
1620 ScriptInstance* i = ScriptInstance_Check(L);
1621 Instance* instance = i->m_Instance;
1622 dmMessage::URL sender;
1623 dmScript::GetURL(L, &sender);
1624 dmMessage::URL target;
1625 dmScript::ResolveURL(L, 1, &target, &sender);
1626 HCollection collection = dmGameObject::GetCollection(instance);
1627 if (target.m_Socket != dmGameObject::GetMessageSocket(collection))
1628 {
1629 luaL_error(L, "go.animate can only animate instances within the same collection.");
1630 }
1631 dmhash_t property_id = 0;
1632 if (lua_isstring(L, 2))
1633 {
1634 property_id = dmHashString64(lua_tostring(L, 2));
1635 }
1636 else
1637 {
1638 property_id = dmScript::CheckHash(L, 2);
1639 }
1640 dmGameObject::HInstance target_instance = dmGameObject::GetInstanceFromIdentifier(collection, target.m_Path);
1641 if (target_instance == 0)
1642 return luaL_error(L, "Could not find any instance with id '%s'.", dmHashReverseSafe64Alloc(&hash_ctx, target.m_Path));
1643 lua_Integer playback = luaL_checkinteger(L, 3);
1644 if (playback >= PLAYBACK_COUNT)
1645 return luaL_error(L, "invalid playback mode when starting an animation");
1646 dmGameObject::PropertyVar property_var;
1647 dmGameObject::PropertyResult result = dmGameObject::LuaToVar(L, 4, property_var);
1648 if (result != PROPERTY_RESULT_OK)
1649 {
1650 return luaL_error(L, "only numerical values can be used as target values for animation");
1651 }
1652
1653 dmEasing::Curve curve;
1654 if (lua_isnumber(L, 5))
1655 {
1656 curve.type = (dmEasing::Type)luaL_checkinteger(L, 5);
1657 if (curve.type >= dmEasing::TYPE_COUNT)
1658 return luaL_error(L, "invalid easing constant");
1659 }
1660 else if (dmScript::IsVector(L, 5))
1661 {
1662 curve.type = dmEasing::TYPE_FLOAT_VECTOR;
1663 curve.vector = dmScript::CheckVector(L, 5);
1664
1665 lua_pushvalue(L, 5);
1666 curve.release_callback = LuaCurveRelease;
1667 curve.userdata1 = L;
1668 curve.userdata2 = (void*)(uintptr_t)dmScript::Ref(L, LUA_REGISTRYINDEX);
1669 }
1670 else
1671 {

Callers

nothing calls this directly

Calls 15

lua_gettopFunction · 0.85
ScriptInstance_CheckFunction · 0.85
GetCollectionFunction · 0.85
GetMessageSocketFunction · 0.85
luaL_errorFunction · 0.85
lua_isstringFunction · 0.85
CheckHashFunction · 0.85
dmHashReverseSafe64AllocFunction · 0.85
luaL_checkintegerFunction · 0.85
LuaToVarFunction · 0.85
lua_isnumberFunction · 0.85

Tested by

no test coverage detected