Created
April 13, 2017 06:12
-
-
Save xphere/a7b9e401925020afee7612a562e700cf to your computer and use it in GitHub Desktop.
Demo of https://github.com/godotengine/godot/issues/2314 and fixed workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Area2D | |
func _ready(): | |
if get_tree().is_editor_hint(): | |
return | |
#old_workaround() | |
fixed_workaround() | |
func fixed_workaround(): | |
var children = get_children() | |
get_tree().set_editor_hint(true) | |
for shape in children: | |
remove_child(shape) | |
add_child(shape) | |
if shape extends CollisionShape2D: | |
shape.set_shape(shape.get_shape()) | |
elif shape extends CollisionPolygon2D: | |
shape.set_polygon(shape.get_polygon()) | |
get_tree().set_editor_hint(false) | |
func old_workaround(): | |
for shape in get_children(): | |
get_tree().set_editor_hint(true) | |
remove_child(shape) | |
add_child(shape) | |
get_tree().set_editor_hint(false) | |
if shape extends CollisionShape2D: | |
shape.set_shape(shape.get_shape()) | |
elif shape extends CollisionPolygon2D: | |
shape.set_polygon(shape.get_polygon()) | |
remove_child(shape) | |
add_child(shape) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[gd_scene load_steps=2 format=1] | |
[ext_resource path="res://ExtendsArea2D.gd" type="Script" id=1] | |
[node name="ExtendsArea2D" type="Area2D"] | |
input/pickable = true | |
gravity_vec = Vector2( 0, 1 ) | |
gravity = 98.0 | |
linear_damp = 0.1 | |
angular_damp = 1.0 | |
script/script = ExtResource( 1 ) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
func _ready(): | |
for child in get_children(): | |
report_shapes(child) | |
func report_shapes(node): | |
var shape_count = node.get_shape_count() | |
print(node.get_name(), " node has ", shape_count, " collision shapes in it.") | |
for index in range(0, shape_count): | |
print(" - shape #", index, " = ", node.get_shape(index)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[gd_scene load_steps=7 format=1] | |
[ext_resource path="res://Level.gd" type="Script" id=1] | |
[ext_resource path="res://ExtendsArea2D.tscn" type="PackedScene" id=2] | |
[sub_resource type="CapsuleShape2D" id=3] | |
custom_solver_bias = 0.0 | |
radius = 10.0 | |
height = 20.0 | |
[sub_resource type="RectangleShape2D" id=4] | |
custom_solver_bias = 0.0 | |
extents = Vector2( 10, 10 ) | |
[sub_resource type="CircleShape2D" id=6] | |
custom_solver_bias = 0.0 | |
radius = 10.0 | |
[sub_resource type="CapsuleShape2D" id=5] | |
custom_solver_bias = 0.0 | |
radius = 10.0 | |
height = 20.0 | |
[node name="TopNode" type="Node2D"] | |
script/script = ExtResource( 1 ) | |
[node name="Shapes" parent="." instance=ExtResource( 2 )] | |
transform/pos = Vector2( 60, 0 ) | |
[node name="CollisionShape" type="CollisionShape2D" parent="Shapes"] | |
shape = SubResource( 3 ) | |
trigger = false | |
_update_shape_index = 0 | |
[node name="CollisionShape2D" type="CollisionShape2D" parent="Shapes"] | |
transform/pos = Vector2( -8.67657, 0.695358 ) | |
shape = SubResource( 4 ) | |
trigger = false | |
_update_shape_index = 1 | |
[node name="Polygons" parent="." instance=ExtResource( 2 )] | |
transform/pos = Vector2( 120, 0 ) | |
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Polygons"] | |
build_mode = 0 | |
polygon = Vector2Array( -15.1588, -4.15517, -12.9081, -15.5819, -3.38585, -15.5819, 5.44388, -5.88649, -6.15596, 3.11637 ) | |
shape_range = Vector2( 0, 0 ) | |
trigger = false | |
[node name="CollisionPolygon2D 2" type="CollisionPolygon2D" parent="Polygons"] | |
transform/pos = Vector2( -2.77011, -1.03879 ) | |
build_mode = 0 | |
polygon = Vector2Array( -13.0812, 4.67456, -5.46342, 9.69538, 7.34834, 4.84769, 13.9274, 18.8714, -10.3111, 20.4296 ) | |
shape_range = Vector2( 1, 2 ) | |
trigger = false | |
[node name="Mixed" parent="." instance=ExtResource( 2 )] | |
transform/pos = Vector2( 180, 0 ) | |
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Mixed"] | |
build_mode = 0 | |
polygon = Vector2Array( -15.1588, -4.15517, -12.9081, -15.5819, -3.38585, -15.5819, 5.44388, -5.88649, -6.15596, 3.11637 ) | |
shape_range = Vector2( 0, 0 ) | |
trigger = false | |
[node name="CollisionShape2D" type="CollisionShape2D" parent="Mixed"] | |
transform/pos = Vector2( 8.01735, -1.9436 ) | |
shape = SubResource( 6 ) | |
trigger = false | |
_update_shape_index = 1 | |
[node name="CollisionPolygon2D 2" type="CollisionPolygon2D" parent="Mixed"] | |
transform/pos = Vector2( -2.77011, -1.03879 ) | |
build_mode = 0 | |
polygon = Vector2Array( -13.0812, 4.67456, -5.46342, 9.69538, 7.34834, 4.84769, 13.9274, 18.8714, -10.3111, 20.4296 ) | |
shape_range = Vector2( 2, 3 ) | |
trigger = false | |
[node name="Area2D" type="Area2D" parent="."] | |
input/pickable = true | |
shapes/0/shape = SubResource( 5 ) | |
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) | |
shapes/0/trigger = false | |
gravity_vec = Vector2( 0, 1 ) | |
gravity = 98.0 | |
linear_damp = 0.1 | |
angular_damp = 1.0 | |
[node name="CollisionShape" type="CollisionShape2D" parent="Area2D"] | |
shape = SubResource( 5 ) | |
trigger = false | |
_update_shape_index = 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment