Skip to content

Commit 029706d

Browse files
authored
Merge pull request #356 from pigdevstudio/add-script-instancing
Add Ball Factory
2 parents 2490d9a + 1ae9f1b commit 029706d

File tree

6 files changed

+30
-38
lines changed

6 files changed

+30
-38
lines changed

misc/instancing/ball_factory.gd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends Position2D
2+
3+
export (PackedScene) var ball_scene = preload("res://ball.tscn")
4+
5+
func _unhandled_input(event):
6+
if event.is_echo():
7+
return
8+
if event is InputEventMouseButton and event.is_pressed():
9+
if event.button_index == BUTTON_LEFT:
10+
spawn(get_global_mouse_position())
11+
12+
13+
func spawn(spawn_global_position = global_position):
14+
var instance = ball_scene.instance()
15+
instance.global_position = spawn_global_position
16+
add_child(instance)

misc/instancing/bowling_ball.png.import

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
importer="texture"
44
type="StreamTexture"
55
path="res://.import/bowling_ball.png-0fe48f78a8537b41cee7fd03e5ee14fe.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
69

710
[deps]
811

misc/instancing/container.png

-6.69 KB
Binary file not shown.

misc/instancing/container.png.import

Lines changed: 0 additions & 31 deletions
This file was deleted.

misc/instancing/container.tscn

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[gd_scene load_steps=13 format=2]
22

3-
[ext_resource path="res://container.png" type="Texture" id=1]
3+
[ext_resource path="res://ball_factory.gd" type="Script" id=1]
44
[ext_resource path="res://ball.tscn" type="PackedScene" id=2]
55

66
[sub_resource type="PhysicsMaterial" id=1]
@@ -35,16 +35,18 @@ bounce = 0.4
3535

3636
[node name="container" type="Node"]
3737

38-
[node name="static" type="StaticBody2D" parent="."]
38+
[node name="ball_factory" type="Position2D" parent="."]
39+
script = ExtResource( 1 )
3940

40-
[node name="sprite" type="Sprite" parent="static"]
41-
position = Vector2( 3, -4 )
42-
texture = ExtResource( 1 )
43-
centered = false
41+
[node name="static" type="StaticBody2D" parent="."]
4442

4543
[node name="collision" type="CollisionPolygon2D" parent="static"]
4644
polygon = PoolVector2Array( 8.68994, 22.1976, 50.4445, 556.656, 292.621, 501.54, 335.36, 550.855, 510.039, 563.135, 542.137, 526.368, 567.463, 515.822, 612.463, 506.822, 667.291, 495.079, 747.553, 553.575, 793.806, 6.70509, 802.465, 601.097, 4.43558, 596.186 )
4745

46+
[node name="polygon2d" type="Polygon2D" parent="static"]
47+
color = Color( 1, 0.266667, 0.419608, 1 )
48+
polygon = PoolVector2Array( 8.68994, 22.1976, 50.4445, 556.656, 292.621, 501.54, 335.36, 550.855, 510.039, 563.135, 542.137, 526.368, 567.463, 515.822, 612.463, 506.822, 667.291, 495.079, 747.553, 553.575, 793.806, 6.70509, 802.465, 601.097, 4.43558, 596.186 )
49+
4850
[node name="ball 1" parent="." instance=ExtResource( 2 )]
4951
position = Vector2( 223.823, 161.773 )
5052
physics_material_override = SubResource( 1 )
@@ -84,4 +86,3 @@ physics_material_override = SubResource( 9 )
8486
[node name="ball 10" parent="." instance=ExtResource( 2 )]
8587
position = Vector2( 143.756, 295.139 )
8688
physics_material_override = SubResource( 10 )
87-

misc/instancing/icon.png.import

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
importer="texture"
44
type="StreamTexture"
55
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
69

710
[deps]
811

0 commit comments

Comments
 (0)