Skip to content

Commit

Permalink
using get_ysort_yposition()
Browse files Browse the repository at this point in the history
  • Loading branch information
e-e committed May 26, 2019
1 parent a55000a commit 3e4a4a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions BetterYSort.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ func flatten():
func _process(delta : float):
_sort()

# this can be overridden to define how you want certain nodes to be sorted
# each item in `children` needs to be an array with to elements: the y-position to sort on
# and the node which should be moved in the tree
# any node that implements the `get_ysort_yposition` takes control
# of which position will be used during the sort
func get_sort_array() -> Array:
var children : Array = []

for child in get_children():
var data : Array = []
if child is Path2D:
var sort_node : PathFollow2D = child.get_children()[0]
data = [sort_node.global_position.y, child]
if child.has_method('get_ysort_yposition'):
data = [node.get_ysort_yposition(), child]
else:
data = [child.global_position.y, child]

Expand Down
4 changes: 2 additions & 2 deletions example/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ rotate = false
script = ExtResource( 3 )

[node name="Entity5" parent="BetterYSort/Path2D/PathFollow2D" instance=ExtResource( 2 )]
position = Vector2( 7.62939e-06, 3.05176e-05 )
rotation = 9.31322e-10
position = Vector2( 7.62939e-006, 3.05176e-005 )
rotation = 9.31322e-010

0 comments on commit 3e4a4a0

Please sign in to comment.