Added cast animation and z index support for the sheet generator script. For some reason z-indexes are acting up though, so the generated sheets have some artifacts. Might be a bug in godot, not sure.

This commit is contained in:
Relintai 2021-07-15 00:05:34 +02:00
parent 74bc71579a
commit f45e7d297f
5 changed files with 72 additions and 14 deletions

View File

@ -2191,7 +2191,7 @@ region_enabled = true
region_rect = Rect2( 27, 57, 14, 6 )
[node name="Torso" type="Sprite" parent="Hip"]
position = Vector2( 0, -2.05287 )
position = Vector2( 0, -2.16791 )
texture = ExtResource( 1 )
offset = Vector2( 0, -5 )
region_enabled = true
@ -2201,7 +2201,7 @@ __meta__ = {
}
[node name="leg_r" type="Sprite" parent="Hip/Torso"]
position = Vector2( -2, 1 )
position = Vector2( -2, 0.999999 )
rotation = -0.0158546
texture = ExtResource( 1 )
offset = Vector2( 0, 3 )

View File

@ -32,18 +32,21 @@ character_atlas = ExtResource( 1 )
visible = false
[node name="Torso" parent="CharacterFrontModel/Hip" index="1"]
position = Vector2( 0, -2.29163 )
position = Vector2( 0, -2.33066 )
[node name="leg_r" parent="CharacterFrontModel/Hip/Torso" index="0"]
position = Vector2( -2, 1 )
[node name="CharacterSideModel" parent="." instance=ExtResource( 5 )]
[node name="arm_r" parent="CharacterSideModel" index="0"]
position = Vector2( -3.49999, -24.1979 )
position = Vector2( -3.49998, -24.142 )
[node name="hand_r" parent="CharacterSideModel" index="1"]
position = Vector2( -3.49999, -18.6979 )
position = Vector2( -3.49998, -18.642 )
[node name="Torso" parent="CharacterSideModel/Hip" index="3"]
position = Vector2( 5.07217e-05, -1.58236 )
position = Vector2( 5.75098e-05, -1.52647 )
[editable path="CharacterFrontModel"]
[editable path="CharacterSideModel"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://characters/CharacterFrontModel.tscn" type="PackedScene" id=1]
[ext_resource path="res://characters/CharacterSideModel.tscn" type="PackedScene" id=2]
@ -6,6 +6,7 @@
[ext_resource path="res://testsave.png" type="Texture" id=4]
[ext_resource path="res://spritesheet_generator/SpriteMover.gd" type="Script" id=5]
[ext_resource path="res://characters/naturalist_characteratlas.tres" type="CharacterAtlas" id=6]
[ext_resource path="res://modules/entity_classes/naturalist/spell_effects/nature2d/NatureCast.tscn" type="PackedScene" id=7]
[sub_resource type="Environment" id=1]
ssao_enabled = true
@ -20,6 +21,7 @@ _sprite_num = 16
_show_atlas = true
save_texture = true
animations = [ "run", "idle", "casting", "rest" ]
z_index_paths = [ NodePath("Viewport/CharacterFrontModel/Hip/Torso/remote_arm_r/remote_hand_r"), NodePath("Viewport/CharacterFrontModel/Hip/Torso/arm_l/hand_l") ]
instant_preview_path = NodePath("InstantPreview")
sprite_preview_path = NodePath("SpritePreview")
viewport_path = NodePath("Viewport")
@ -30,6 +32,9 @@ model_front_animation_tree_player_path = NodePath("Viewport/CharacterFrontModel/
model_side_path = NodePath("Viewport/CharacterSideModel")
model_side_animation_player_path = NodePath("Viewport/CharacterSideModel/AnimationPlayer")
model_side_animation_tree_player_path = NodePath("Viewport/CharacterSideModel/AnimationTree")
cast_animation_index = 2
cast_animation_scene = ExtResource( 7 )
cast_animation_paths = [ NodePath("Viewport/CharacterFrontModel/Hip/Torso/remote_arm_r/remote_hand_r/Position2D"), NodePath("Viewport/CharacterFrontModel/Hip/Torso/arm_l/hand_l/end"), NodePath("Viewport/CharacterSideModel/Hip/Torso/remote_arm_r/remote_hand_r/Position2D"), NodePath("Viewport/CharacterSideModel/Hip/Torso/arm_l/hand_l/end") ]
[node name="Viewport" type="Viewport" parent="."]
size = Vector2( 64, 64 )
@ -44,10 +49,10 @@ render_target_update_mode = 3
[node name="Camera" type="Camera2D" parent="Viewport"]
position = Vector2( 0, -15.726 )
z_index = 2
current = true
[node name="CharacterFrontModel" parent="Viewport" instance=ExtResource( 1 )]
visible = false
_atlas = ExtResource( 6 )
[node name="Torso" parent="Viewport/CharacterFrontModel/Hip" index="1"]
@ -60,6 +65,7 @@ z_index = 1
active = false
[node name="CharacterSideModel" parent="Viewport" instance=ExtResource( 2 )]
visible = false
rotation = 3.14147
scale = Vector2( 1, -1 )
_atlas = ExtResource( 6 )

View File

@ -13,6 +13,7 @@ export (bool) var generate : bool = false setget set_generate, get_generate
export (String) var output_file_name : String = "res://testsave.png"
export (Array, String) var animations : Array
export (Array, NodePath) var z_index_paths : Array
export (NodePath) var instant_preview_path
export (NodePath) var sprite_preview_path
@ -26,6 +27,10 @@ export (NodePath) var model_side_path
export (NodePath) var model_side_animation_player_path
export (NodePath) var model_side_animation_tree_player_path
export(int) var cast_animation_index : int = 0
export(PackedScene) var cast_animation_scene : PackedScene = null
export (Array, NodePath) var cast_animation_paths : Array
var cast_animations : Array
var _viewport
var _viewport_texture
@ -105,8 +110,7 @@ func _process(delta):
setup_direction()
_current_animation_player.play(animations[_current_animation_index])
_current_animation_player.seek(0, true)
setup_animation()
return
@ -133,9 +137,9 @@ func _process(delta):
_running = false
create_atlas()
return
setup_animation()
_current_animation_player.play(animations[_current_animation_index])
_current_animation_player.seek(0, true)
return
var ur = frame.get_used_rect()
@ -148,6 +152,31 @@ func _process(delta):
_frame += 1
func setup_animation():
_current_animation_player.play(animations[_current_animation_index])
_current_animation_player.seek(0, true)
if !cast_animation_scene:
return
if _current_animation_index == cast_animation_index:
for cap in cast_animation_paths:
var n = get_node(cap)
if !n:
continue
var pa = cast_animation_scene.instance()
cast_animations.push_back(pa)
n.add_child(pa)
else:
for n in cast_animations:
n.queue_free()
cast_animations.clear()
#enum CharacterFacing
# FACING_FRONT = 0,
# FACING_BACK = 1,
@ -155,26 +184,39 @@ func _process(delta):
# FACING_LEFT = 3,
func setup_direction():
for a in cast_animations:
if a.has_method("get_z_index"):
a.z_index = 0
if _direction == 0:
_current_animation_player = _model_side_animation_player
_model_side.set_facing(2)
_model_side.transform.x.x = -1
_model_side.show()
_model_front.hide()
for np in z_index_paths:
get_node(np).z_index = 0
if _direction == 1:
_current_animation_player = _model_side_animation_player
_model_side.set_facing(3)
_model_side.transform.x.x = 1
_model_side.show()
_model_front.hide()
for np in z_index_paths:
get_node(np).z_index = 0
if _direction == 2:
_current_animation_player = _model_front_animation_player
_model_front.set_facing(0)
_model_side.hide()
_model_front.show()
for np in z_index_paths:
get_node(np).z_index = 0
if _direction == 3:
_current_animation_player = _model_front_animation_player
_model_front.set_facing(1)
@ -182,6 +224,13 @@ func setup_direction():
_model_side.hide()
_model_front.show()
for np in z_index_paths:
get_node(np).z_index = -1
for a in cast_animations:
if a.has_method("get_z_index"):
a.z_index = -1
func create_atlas():
_image_texture = ImageTexture.new()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 42 KiB