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

Function LuaAnimate

engine/gui/src/gui_script.cpp:1487–1582  ·  view source on GitHub ↗

animates a node property * This starts an animation of a node property according to the specified parameters. * If the node property is already being animated, that animation will be canceled and * replaced by the new one. Note however that several different node properties * can be animated simultaneously. Use `gui.cancel_animations` to stop the animation * before it has

Source from the content-addressed store, hash-verified

1485 * ```
1486 */
1487 static int LuaAnimate(lua_State* L)
1488 {
1489 DM_LUA_STACK_CHECK(L, 0);
1490
1491 Scene* scene = GuiScriptInstance_Check(L);
1492
1493 HNode hnode;
1494 InternalNode* node = LuaCheckNodeInternal(L, 1, &hnode);
1495 (void) node;
1496
1497 dmhash_t property_hash = dmScript::CheckHashOrString(L, 2);
1498 if (!dmGui::HasPropertyHash(scene, hnode, property_hash)) {
1499 char buffer[128];
1500 luaL_error(L, "property '%s' not found", dmScript::GetStringFromHashOrString(L, 2, buffer, sizeof(buffer)));
1501 }
1502
1503 Vector3* v3;
1504 Quat* q;
1505 Vector4 to;
1506 if (lua_isnumber(L, 3))
1507 {
1508 to = Vector4((float) lua_tonumber(L, 3));
1509 }
1510 else if ((v3 = dmScript::ToVector3(L, 3)))
1511 {
1512 Vector4 original = dmGui::GetNodePropertyHash(scene, hnode, property_hash);
1513 to = Vector4(*v3, original.getW());
1514 }
1515 else if ((q = dmScript::ToQuat(L, 3)))
1516 {
1517 to = Vector4(*q);
1518 }
1519 else
1520 {
1521 to = *dmScript::CheckVector4(L, 3);
1522 }
1523
1524 dmEasing::Curve curve;
1525 if (lua_isnumber(L, 4))
1526 {
1527 curve.type = (dmEasing::Type)luaL_checkinteger(L, 4);
1528 if (curve.type >= dmEasing::TYPE_COUNT)
1529 return luaL_error(L, "invalid easing constant");
1530 }
1531 else if (dmScript::IsVector(L, 4))
1532 {
1533 curve.type = dmEasing::TYPE_FLOAT_VECTOR;
1534 curve.vector = dmScript::CheckVector(L, 4);
1535
1536 lua_rawgeti(L, LUA_REGISTRYINDEX, scene->m_ContextTableReference);
1537 lua_pushvalue(L, 4);
1538
1539 curve.release_callback = LuaCurveRelease;
1540 curve.userdata1 = (void*)scene;
1541 curve.userdata2 = (void*)(uintptr_t)dmScript::Ref(L, -2);
1542 lua_pop(L, 1);
1543 }
1544 else

Callers

nothing calls this directly

Calls 15

GuiScriptInstance_CheckFunction · 0.85
LuaCheckNodeInternalFunction · 0.85
CheckHashOrStringFunction · 0.85
luaL_errorFunction · 0.85
lua_isnumberFunction · 0.85
lua_tonumberFunction · 0.85
ToVector3Function · 0.85
ToQuatFunction · 0.85
CheckVector4Function · 0.85
luaL_checkintegerFunction · 0.85
IsVectorFunction · 0.85

Tested by

no test coverage detected