From cf7e4b31f4fbee912533e099a8d8ec1f124f1883 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Thu, 11 Mar 2021 14:31:18 +0300 Subject: [PATCH] Small improvement for Bullet Shower Demo --- 2d/bullet_shower/bullets.gd | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/2d/bullet_shower/bullets.gd b/2d/bullet_shower/bullets.gd index ee1a5fe0..7144925d 100644 --- a/2d/bullet_shower/bullets.gd +++ b/2d/bullet_shower/bullets.gd @@ -52,22 +52,25 @@ func _ready(): bullets.push_back(bullet) -func _process(delta): +func _process(_delta): + # Order the CanvasItem to update every frame. + update() + + +func _physics_process(delta): var transform2d = Transform2D() + var offset = get_viewport_rect().size.x + 16 for bullet in bullets: bullet.position.x -= bullet.speed * delta if bullet.position.x < -16: # The bullet has left the screen; move it back to the right. - bullet.position.x = get_viewport_rect().size.x + 16 + bullet.position.x = offset transform2d.origin = bullet.position Physics2DServer.body_set_state(bullet.body, Physics2DServer.BODY_STATE_TRANSFORM, transform2d) - # Order the CanvasItem to update since bullets are moving every frame. - update() - # Instead of drawing each bullet individually in a script attached to each bullet, # we are drawing *all* the bullets at once here.