# Spawn phase for i in range(10): var sprite = ServerSpriteGD.new() sprite.rid = RenderingServer.canvas_item_create() RenderingServer.canvas_item_set_parent(sprite.rid, get_canvas_item()) RenderingServer.canvas_item_set_draw_index(sprite.rid, len(sprites)) var rect = Rect2(0, 0, texture.get_width(), texture.get_height()) RenderingServer.canvas_item_add_texture_rect(sprite.rid, rect, texture.get_rid()) var speed = 200 var direction = angle + i * (deg_to_rad(360)) / 10 sprite.position = Vector2(640, 360) sprite.velocity = Vector2(cos(direction), sin(direction)) * speed sprites.append(sprite) angle += deg_to_rad(2) # Update phase for sprite in sprites: sprite.position += sprite.velocity * delta if sprite.position.x < 0.0: sprite.velocity.x = -sprite.velocity.x elif sprite.position.x > 1280.0: sprite.velocity.x = -sprite.velocity.x if sprite.position.y < 0.0: sprite.velocity.y = -sprite.velocity.y elif sprite.position.y > 720.0: sprite.velocity.y = -sprite.velocity.y var sprite_transform = Transform2D(0.0, Vector2(0.25, 0.25), 0.0, sprite.position) RenderingServer.canvas_item_set_transform(sprite.rid, sprite_transform) void SpriteServerCpp::_process(float delta) { auto rs = RenderingServer::get_singleton(); if (spawn) { // Spawn phase for (int i = 0; i < 10; i++) { auto sprite = ServerSpriteCpp(); sprite.rid = rs->canvas_item_create(); rs->canvas_item_set_parent(sprite.rid, get_canvas_item()); rs->canvas_item_set_draw_index(sprite.rid, (int)sprites.size()); Rect2 rect = Rect2(0, 0, texture->get_width(), texture->get_height()); rs->canvas_item_add_texture_rect(sprite.rid, rect, texture->get_rid()); float speed = 200.0f; float direction = angle + i * (UtilityFunctions::deg_to_rad(360.0f)) / 10.0f; sprite.position = Vector2(640, 360); sprite.velocity = Vector2(cos(direction), sin(direction)) * speed; sprites.emplace_back(sprite); } angle += UtilityFunctions::deg_to_rad(2); } // Update phase for (auto& sprite : sprites) { sprite.position += sprite.velocity * delta; if (sprite.position.x < 0.0) { sprite.velocity.x = -sprite.velocity.x; } else if (sprite.position.x > 1280.0) { sprite.velocity.x = -sprite.velocity.x; } if (sprite.position.y < 0.0) { sprite.velocity.y = -sprite.velocity.y; } else if (sprite.position.y > 720.0) { sprite.velocity.y = -sprite.velocity.y; } Transform2D sprite_transform = Transform2D(0.0, Vector2(0.25, 0.25), 0.0, sprite.position); rs->canvas_item_set_transform(sprite.rid, sprite_transform); } }