- Go for it! Align gameobject scaling API to use vector3 as default
- Implement special solution for game object scaling
0 voters
Hello Defold users!
The past few days we in the engine team have been looking at how we handle scaling across the different components in Defold. We want the API to be uniform and easy to use whether you are setting the scale of a game object at init or animating the scale of a sprite in runtime.
The initial task that prompted this discussion was to enable go.animate
on elements in the gameobject scale vector, e.g. do:
go.animate(".", "scale.x", go.PLAYBACK_ONCE_FORWARD, 1, go.EASING_LINEAR, 1, 0)
Overview
Currently the API to set scale on a game object looks like this:
go.set(“.”, “scale”, 2.0) FLOAT
go.set_scale(2.0) FLOAT
go.set_scale(vmath.vector3(1.0, 2.0, 3.0)) VECTOR3
go.get(“.”, “scale”) FLOAT
go.get_scale() FLOAT
go.get_scale_vector() VECTOR3
In the beginning it was only possible to do uniform scaling of game objects. When the need arose to do non-uniform scaling go.set_scale
was added that takes both float and vector3. The value can be retrieved with go.get_scale()
(float) or go.get_scale_vector()
(vector3).
To fulfil backward compatibility go.set
and go.get
still return floats instead of the scaling vector3.
Taking a step back and looking at the API; We now have a go property "scale"
that will return a float when used with go set/get, but is really a vector3 in every other sense. Adding the possibility to animate for example “scale.x” means that we have a property that is a float in some cases, but has elements that you can animate!
Solution
After some discussion within the team it really makes sense to straighten out the API now rather than create more special properties and pollute the API with more ways to handle scaling. We would like the handling of scale for gameobjects to align with how scale is handled for example in sprite- and label-components. So rather than introduce special solutions to this problem, we want to:
- Flip the current API, default to vector3 instead of uniform scale factor
-
go.set
will take both float and vector3 -
go.get
will return vector3 instead of float -
go.get_scale()
will return vector3 instead of float - Deprecate
go.get_scale_vector()
and add functiongo.get_scale_uniform()
instead.
This will result in
- The
"scale"
property is treated as a vector3 throughout - It is very explicit when the user get a uniform scale instead of the vector
- Better alignment with scaling on other components instead of making a special for this specific case
- Breaking somewhat backward compatibility since
go.get
will return a vector3 instead of a float
Since we make this engine for you who are using it we would very much like to here what the forums think of this. Please post any thoughts you have and please fill out the poll
//Johan and the Defold team