-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port the Bullet Shower demo from Godot 2.1 #588
Port the Bullet Shower demo from Godot 2.1 #588
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the code looks good. I noticed that @reduz said here that this is "very far from being the most optimized form", so I wonder if there are ways to optimize this further without engine changes (if so, that should be done in this demo).
The images can be compressed with oxipng for slightly less file size: bullet-shower-images.zip
616ee1b
to
e38e001
Compare
The code in extends Node2D
# This demo is an example of controling a high number of 2D objects with logic
# and collision without using nodes in the scene. This technique is a lot more
# efficient than using instancing and nodes, but requires more programming and
# is less visual. Bullets are managed together in the `bullets.gd` script.
# The number of bullets currently touched by the player.
var touching = 0
onready var sprite = $AnimatedSprite
func _ready():
# The player follows the mouse cursor automatically, so there's no point
# in displaying the mouse cursor.
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
func _input(event):
if event is InputEventMouseMotion:
position = event.position - Vector2(0, 16)
func _on_player_body_shape_entered(_body_id, _body, _body_shape, _local_shape):
touching += 1
if touching >= 1:
sprite.frame = 1
func _on_player_body_shape_exited(_body_id, _body, _body_shape, _local_shape):
touching -= 1
if touching == 0:
sprite.frame = 0 + delete |
This demo showcases how to use low-level Servers to achieve better CPU performance when drawing large amounts of objects. The code has been updated for Godot 3.2, cleaned up and has received additional comments.
e38e001
to
ca0f74e
Compare
The bullets in this example are all set to the default collision layer so I think they are checking collisions with each other. Adding My hardware isn't great, but I can build the same example with 7 lines of code in Construct 3 and can have 15000 bullets without dropping frames. |
See https://github.com/cart/godot3-bunnymark. I would try building this Bullet Shower demo with nodes and see how it performs in comparison to the demo that uses servers. Due to how servers work currently, they don't bring much of a performance advantage since most of the time is still spent in the physics server. |
This demo showcases how to use low-level Servers to achieve better CPU performance when drawing large amounts of objects.
The code has been updated for Godot 3.2, cleaned up and has received additional comments.
Preview