From 3d2fde338168be795a5ec6e066ea0eb4f85bc820 Mon Sep 17 00:00:00 2001 From: Haze Weathers Date: Thu, 1 Jan 2026 22:29:40 -0600 Subject: [PATCH] bullet texture animations --- .../bullets/normal_bullet/test_bullet.png | Bin 0 -> 226 bytes .../normal_bullet/test_bullet.png.import | 40 ++++++++++++++++++ .../normal_bullet/test_bullet_overlay.png | Bin 0 -> 170 bytes .../test_bullet_overlay.png.import | 40 ++++++++++++++++++ scenes/test_scene_haze.tscn | 23 ++++++++-- systems/bullets/bullet.gd | 32 +++++++++----- .../bullet_behaviors/bullet_behavior.gd | 8 ++-- systems/bullets/bullet_preset.gd | 14 +++++- systems/bullets/bullet_set.gd | 1 + systems/visuals/animation_strip.gd | 19 +++++++++ systems/visuals/animation_strip.gd.uid | 1 + 11 files changed, 160 insertions(+), 18 deletions(-) create mode 100644 graphics/bullets/normal_bullet/test_bullet.png create mode 100644 graphics/bullets/normal_bullet/test_bullet.png.import create mode 100644 graphics/bullets/normal_bullet/test_bullet_overlay.png create mode 100644 graphics/bullets/normal_bullet/test_bullet_overlay.png.import create mode 100644 systems/visuals/animation_strip.gd create mode 100644 systems/visuals/animation_strip.gd.uid diff --git a/graphics/bullets/normal_bullet/test_bullet.png b/graphics/bullets/normal_bullet/test_bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..8a46c18d6ba6d78b50774a89b4664da215439d11 GIT binary patch literal 226 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~c!3HEhl+{lMQjEnx?oNz1PwLbIIV|apzK#qG z8~eHcB(ehe3dtTpz6=aiY77hwEes65fI z>Ealoaeir_Bi{i7j!Q@DUtWHF`i`qu((Yi(g#jL`ybj;>=9szC=Ko7JL#31j2~B+G zqh4R`mEXLuGVwfPOj5$-3%c&T-Euoy=1R@{eCF(p$odf1BVta|S4eWi=AZw;EaloaXvXgBItp=h(fpFBJBhaNJ&XKvP{xdIfVCeLv`W void: _update_visibility_notifier() -func _physics_process(delta: float) -> void: +func _physics_process(_delta: float) -> void: if not Engine.is_editor_hint(): + queue_redraw() if face_direction: rotation = direction.angle() func _draw() -> void: - if texture: - draw_texture(texture, -texture.get_size() * 0.5) + if base_graphic: + base_graphic.draw(self, time_elapsed, color) + if overlay_graphic: + overlay_graphic.draw(self, time_elapsed, Color.WHITE) func _get_configuration_warnings() -> PackedStringArray: @@ -121,14 +133,14 @@ func _get_configuration_warnings() -> PackedStringArray: # sets the canvas item up to notify when it leaves the screen # this essentially mimics `VisibleOnScreenNotifier` without an additional node func _update_visibility_notifier() -> void: - if not texture or not is_inside_tree() or Engine.is_editor_hint(): + if not base_graphic or not base_graphic.texture or not is_inside_tree() or Engine.is_editor_hint(): return # the visibility rect is set to twice the size of the texture to add a little margin # (func(): pass) is the cleanest way i could think of to have a callback that does nothing RenderingServer.canvas_item_set_visibility_notifier( get_canvas_item(), true, - Rect2(-texture.get_size(), texture.get_size() * 2.0), + Rect2(-base_graphic.texture.get_size(), base_graphic.texture.get_size() * 2.0), (func(): pass), _on_screen_exited ) diff --git a/systems/bullets/bullet_behaviors/bullet_behavior.gd b/systems/bullets/bullet_behaviors/bullet_behavior.gd index 73f5a7b..8c0e2f3 100644 --- a/systems/bullets/bullet_behaviors/bullet_behavior.gd +++ b/systems/bullets/bullet_behaviors/bullet_behavior.gd @@ -33,10 +33,10 @@ func deinit_bullet(bullet: Bullet) -> void: ## Processes one tick of a [Bullet]'s movement. func process_bullet(bullet: Bullet, delta: float) -> void: - var last_time = bullet.time_elapsed - bullet.time_elapsed += delta - if last_time < action_delay and bullet.time_elapsed >= action_delay and action_on_delay: - action_on_delay.perform(bullet) + #var last_time = bullet.time_elapsed + #bullet.time_elapsed += delta + #if last_time < action_delay and bullet.time_elapsed >= action_delay and action_on_delay: + #action_on_delay.perform(bullet) if action_on_interval: _bullet_interval_cooldowns[bullet] -= delta if _bullet_interval_cooldowns[bullet] <= 0.0: diff --git a/systems/bullets/bullet_preset.gd b/systems/bullets/bullet_preset.gd index a7a3d86..03a1e54 100644 --- a/systems/bullets/bullet_preset.gd +++ b/systems/bullets/bullet_preset.gd @@ -1,10 +1,22 @@ +@tool class_name BulletPreset extends Resource @export_group("Bullets") @export var behavior: BulletBehavior = null -@export var textures: Array[Texture2D] = [] +@export var base_graphics: Array[AnimationStrip] = []: + set(value): + base_graphics = value + if base_graphics.size() != overlay_graphics.size(): + overlay_graphics.resize(base_graphics.size()) + notify_property_list_changed() +@export var overlay_graphics: Array[AnimationStrip] = []: + set(value): + overlay_graphics = value + if base_graphics.size() != overlay_graphics.size(): + overlay_graphics.resize(base_graphics.size()) + notify_property_list_changed() @export var colors: Array[Color] = [Color.WHITE] @export var hitbox_size: Vector2i = Vector2i.ZERO @export var face_direction: bool = false diff --git a/systems/bullets/bullet_set.gd b/systems/bullets/bullet_set.gd index 5e64bb9..766fd32 100644 --- a/systems/bullets/bullet_set.gd +++ b/systems/bullets/bullet_set.gd @@ -22,6 +22,7 @@ func _physics_process(delta: float) -> void: for bullet in get_children(): if bullet is Bullet: + bullet.time_elapsed += delta preset.behavior.process_bullet(bullet, delta) diff --git a/systems/visuals/animation_strip.gd b/systems/visuals/animation_strip.gd new file mode 100644 index 0000000..0d190a0 --- /dev/null +++ b/systems/visuals/animation_strip.gd @@ -0,0 +1,19 @@ +class_name AnimationStrip +extends Resource + + +@export var texture: Texture +@export var frames: int = 1 +@export var fps: float = 1.0 + + +func draw(canvas_item: CanvasItem, time: float, modulate: Color = Color.WHITE) -> void: + var frame_size = Vector2((texture.get_width() / frames), float(texture.get_height())) + var current_frame = fmod(floorf(time * fps), frames) + print(time * fps) + canvas_item.draw_texture_rect_region( + texture, + Rect2(-frame_size * 0.5, frame_size), + Rect2(Vector2(current_frame * frame_size.x, 0.0), frame_size), + modulate + ) diff --git a/systems/visuals/animation_strip.gd.uid b/systems/visuals/animation_strip.gd.uid new file mode 100644 index 0000000..8a94175 --- /dev/null +++ b/systems/visuals/animation_strip.gd.uid @@ -0,0 +1 @@ +uid://0ognvvq2ncd7