summaryrefslogtreecommitdiff
path: root/sprite.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-12-12 02:12:52 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-12-12 02:12:52 +0100
commita22381eff3bf2286ee27f4d15ddf4c431ea063be (patch)
tree965bdcf12e5e0cf63c88cbba1bd5a52ba474f81f /sprite.gd
parente3c185e05823e30eccd7728ceda2ee57cc66fd4d (diff)
next commit
Diffstat (limited to 'sprite.gd')
-rw-r--r--sprite.gd14
1 files changed, 5 insertions, 9 deletions
diff --git a/sprite.gd b/sprite.gd
index 3bfc961..745a86d 100644
--- a/sprite.gd
+++ b/sprite.gd
@@ -2,7 +2,7 @@ class_name Sprite
extends Node2D
-var sprite_data: SpriteResource
+@export var sprite_data: SpriteResource
var action_data: ActionFormat
var current_action_idx := 0
@@ -21,16 +21,13 @@ func _ready() -> void:
func load_file(path: String):
var basename = path.get_basename()
- sprite_data = load("%s.tres" % basename)
+ sprite_data = load("%s/sprite.tres" % basename)
var act = FileAccess.open("%s.act" % basename, FileAccess.READ)
action_data = ActionFormat.from_bytes(ByteStream.from_bytes(
act.get_buffer(act.get_length())
))
- if not sprite_data.files_exist():
- sprite_data.save_to_file() # generate at "runtime"
-
set_process(true)
set_current_action(0)
@@ -71,19 +68,18 @@ func update(sprite_layers: Array[ActionFormat.SpriteLayer]):
for idx in sprite_layers.size():
var sprite_layer = sprite_layers[idx]
-
- var base_dir = sprite_data.filepath.substr(0, sprite_data.filepath.length() - 4) # cut off .spr
- var image = load("%s/%s.png" % [base_dir, str(sprite_layer.sprite_index).pad_zeros(3)])
+ var image = sprite_data.images[sprite_layer.sprite_index]
var sprite: Sprite2D
if has_different_layer_count:
sprite = Sprite2D.new()
+ sprite.centered = false # 必要!!
sprite.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
else:
sprite = %SpriteLayers.get_child(idx)
sprite.texture = image
- sprite.position = sprite_layer.get_position()
+ sprite.position = sprite_layer.get_position() - ceil(sprite_layer.get_size() / 2) # for fixing half pixel drawing
sprite.self_modulate = sprite_layer.get_color()
sprite.scale = sprite_layer.get_scale()
sprite.rotation_degrees = sprite_layer.rotation_degrees