mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2025-12-31 09:49:06 +03:00
Merge pull request #595 from dalexeev/bullet-shower-improve
Small improvement for Bullet Shower Demo
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user