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

Function Script_SetScaleXY

engine/gameobject/src/gameobject/gameobject_script.cpp:1105–1130  ·  view source on GitHub ↗

sets the scale factor only for width and height (x and y) of the game object instance * The scale factor is relative to the parent (if any). The global world scale factor cannot be manually set. * * [icon:attention] See manual to know how physics affected when setting scale from this function. * * @name go.s

Source from the content-addressed store, hash-verified

1103 * ```
1104 */
1105 static int Script_SetScaleXY(lua_State* L)
1106 {
1107 Instance* instance = ResolveInstance(L, 2);
1108
1109 // Supports both vector and number
1110 Vector3* v = dmScript::ToVector3(L, 1);
1111 if (v != 0)
1112 {
1113 Vector3 scale = *v;
1114 if (scale.getX() <= 0.0f || scale.getY() <= 0.0f)
1115 {
1116 return luaL_error(L, "Vector passed to go.set_scale_xy contains components that are below or equal to zero");
1117 }
1118 dmGameObject::SetScaleXY(instance, scale.getX(), scale.getY());
1119 return 0;
1120 }
1121
1122 lua_Number n = luaL_checknumber(L, 1);
1123 if (n <= 0.0)
1124 {
1125 return luaL_error(L, "The scale supplied to go.set_scale_xy must be greater than 0.");
1126 }
1127 float value = (float)n;
1128 dmGameObject::SetScaleXY(instance, value, value);
1129 return 0;
1130 }
1131
1132 /*# sets the parent for a specific game object instance
1133 * Sets the parent for a game object instance. This means that the instance will exist in the geometrical space of its parent,

Callers

nothing calls this directly

Calls 7

ResolveInstanceFunction · 0.85
ToVector3Function · 0.85
luaL_errorFunction · 0.85
SetScaleXYFunction · 0.85
luaL_checknumberFunction · 0.85
getXMethod · 0.45
getYMethod · 0.45

Tested by

no test coverage detected