Skip to content

Commit 0210702

Browse files
authored
Merge pull request #595 from dalexeev/bullet-shower-improve
Small improvement for Bullet Shower Demo
2 parents ac61cba + cf7e4b3 commit 0210702

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

2d/bullet_shower/bullets.gd

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,25 @@ func _ready():
5252
bullets.push_back(bullet)
5353

5454

55-
func _process(delta):
55+
func _process(_delta):
56+
# Order the CanvasItem to update every frame.
57+
update()
58+
59+
60+
func _physics_process(delta):
5661
var transform2d = Transform2D()
62+
var offset = get_viewport_rect().size.x + 16
5763
for bullet in bullets:
5864
bullet.position.x -= bullet.speed * delta
5965

6066
if bullet.position.x < -16:
6167
# The bullet has left the screen; move it back to the right.
62-
bullet.position.x = get_viewport_rect().size.x + 16
68+
bullet.position.x = offset
6369

6470
transform2d.origin = bullet.position
6571

6672
Physics2DServer.body_set_state(bullet.body, Physics2DServer.BODY_STATE_TRANSFORM, transform2d)
6773

68-
# Order the CanvasItem to update since bullets are moving every frame.
69-
update()
70-
7174

7275
# Instead of drawing each bullet individually in a script attached to each bullet,
7376
# we are drawing *all* the bullets at once here.

0 commit comments

Comments
 (0)