Add center_object function
This commit is contained in:
parent
a8cfbe8d57
commit
c79ac9f430
2 changed files with 16 additions and 0 deletions
|
@ -50,3 +50,16 @@ Converts an array into a string array.
|
||||||
If an item is found that is not of type `String`, an empty array is returned.
|
If an item is found that is not of type `String`, an empty array is returned.
|
||||||
### *Array* <u>stringarray_to_array</u>(*Array[String]* array)
|
### *Array* <u>stringarray_to_array</u>(*Array[String]* array)
|
||||||
Converts a string array into an array.
|
Converts a string array into an array.
|
||||||
|
### *Vector2* <u>center_object</u>(*Vector2* <u>parent_size</u>, *Vector2* <u>child_size</u>)
|
||||||
|
Calculates the center of the child in the area of the parent.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```gdscript
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
var core: Core = get_node("/root/CORE")
|
||||||
|
var misc: CoreBaseModule = core.misc
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
position = misc.center_object(get_parent().size, size)
|
||||||
|
```
|
||||||
|
|
|
@ -79,3 +79,6 @@ func stringarray_to_array(array: Array[String]) -> Array:
|
||||||
output.append(item)
|
output.append(item)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
func center_object(parent_size: Vector2, child_size: Vector2) -> Vector2:
|
||||||
|
return Vector2(parent_size.x/2-child_size.x/2, parent_size.y/2-child_size.y/2)
|
||||||
|
|
Loading…
Reference in a new issue