Started work on a character skeleton that can use the new sheets.

This commit is contained in:
Relintai 2021-07-15 00:42:26 +02:00
parent f45e7d297f
commit 003633ac0f
4 changed files with 111 additions and 1 deletions

View File

@ -0,0 +1,77 @@
extends Sprite
export(bool) var enabled : bool = true
export(float) var timer : float = 0.13
export(int) var _animset = 0
export(int) var _animset_size = 16
export(int) var _animset_count = 16
var _min_frame = 0
var _max_frame = 16 * 16
var x = 0
var y = 0
var _timer : float = 0
var _frame : int = 0
# Called when the node enters the scene tree for the first time.
func _ready():
set_frame(_min_frame)
#_sprite.set_position(Vector2(x, y))
func set_movement_vector(vector):
var a = Vector2(vector.x, vector.z)
a = a.normalized()
var base = Vector2(0, -1)
var angle = a.angle_to(base) + PI
var slice = (2*PI) / _animset_count
var num_slice = int(angle / slice)
set_animset(num_slice)
func set_animset(animest_id):
if (animest_id >= _animset_count):
_animset = _animset_count - 1
if (animest_id < 0):
_animset = 0
_animset = animest_id
#_min_frame = _animset * _animset_size
#_max_frame = _animset * _animset_size + _animset_size
func _process(delta):
#set_animset(_animset)
if not enabled:
set_process(false)
return
timer += delta
if (timer > 0.05):
timer -= 0.05
_frame += 1
if _frame > _animset_size - 1:
_frame = 0
set_frame(_frame + (_animset * _animset_size))
# Called every frame. 'delta' is the elapsed time since the previous frame.
func a_process(delta):
#x += int(delta * 300)
y += int(delta * 200)
if y > 700:
y = -50
set_position(Vector2(x, y))

View File

@ -0,0 +1,13 @@
extends CharacterSkeleton2D
export(NodePath) var sprite_path : NodePath
var _sprite : Sprite
func _ready():
_sprite = get_node(sprite_path)
func get_sprite() -> Sprite:
return _sprite

View File

@ -0,0 +1,16 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://testsave.png" type="Texture" id=1]
[ext_resource path="res://characters/CharacterSprite.gd" type="Script" id=2]
[ext_resource path="res://characters/SheetCharacter.gd" type="Script" id=3]
[node name="SheetCharacter" type="CharacterSkeleton2D"]
script = ExtResource( 3 )
[node name="CharacterSprite" type="Sprite" parent="."]
position = Vector2( 0, -11.906 )
texture = ExtResource( 1 )
hframes = 16
vframes = 16
script = ExtResource( 2 )
timer = 0.05

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://characters/Character.tscn" type="PackedScene" id=1]
[ext_resource path="res://scripts/item_visuals/CharacterAtlasEntry2D.gd" type="Script" id=2]
[ext_resource path="res://scripts/item_visuals/CharacterAtlas2D.gd" type="Script" id=3]
[ext_resource path="res://characters/char_t1_outline_split.png" type="Texture" id=5]
[ext_resource path="res://player/Body.gd" type="Script" id=6]
[ext_resource path="res://characters/SheetCharacter.tscn" type="PackedScene" id=7]
[sub_resource type="CharacterAtlasEntry" id=1]
script = ExtResource( 2 )
@ -50,6 +51,9 @@ radius = 8.0
[node name="Body" type="KinematicBody2D"]
script = ExtResource( 6 )
[node name="SheetCharacter" parent="." instance=ExtResource( 7 )]
visible = false
[node name="Character" parent="." instance=ExtResource( 1 )]
front_node_path = NodePath("../../Body/Character/CharacterFrontModel")
side_node_path = NodePath("../../Body/Character/CharacterSideModel")