1
0
Fork 0

add steps animation

This commit is contained in:
Manu 2021-04-25 02:22:07 +02:00
parent ea15433849
commit 28d4505657
4 changed files with 62 additions and 6 deletions

View File

@ -15,6 +15,7 @@ tile_data = PoolIntArray( 393216, 0, 0, 393217, 0, 0, 393219, 0, 0, 393220, 0, 0
[node name="Player" parent="." index="2" instance=ExtResource( 2 )]
position = Vector2( 800, 440 )
speed = 10.0
tile_position = Vector2( 8, 5 )
grid_path = NodePath("..")
props_path = NodePath("../Props")

View File

@ -13,6 +13,8 @@ onready var grid = get_node(grid_path) as TileMap
onready var props = get_node(props_path) as TileMap
var last_move_time := 0.0
var step_count := 0
var stepped := false
class Movement:
var action: String
@ -73,12 +75,16 @@ func _process(delta):
tile_position += current_movement.direction * delta * speed
var remaining = current_target - tile_position
var remaining : Vector2 = current_target - tile_position
if remaining.dot(current_movement.direction) <= 0:
tile_position = current_target
current_target = null
movement_queue.pop_front()
stepped = false
elif remaining.length() < 0.5 and not stepped:
step_count += 1
stepped = true
update_position()
last_move_time = OS.get_ticks_msec() / 1000.0
@ -89,3 +95,4 @@ func update_position():
func update_animation():
sprite.animation = sprite.animation if movement_queue.empty() else movement_queue.front().animation
sprite.frame = step_count % 2

View File

@ -1,4 +1,4 @@
[gd_resource type="SpriteFrames" load_steps=6 format=2]
[gd_resource type="SpriteFrames" load_steps=18 format=2]
[ext_resource path="res://character.png" type="Texture" id=1]
@ -6,36 +6,84 @@
atlas = ExtResource( 1 )
region = Rect2( 0, 0, 160, 240 )
[sub_resource type="AtlasTexture" id=5]
atlas = ExtResource( 1 )
region = Rect2( 0, 240, 160, 240 )
[sub_resource type="AtlasTexture" id=6]
atlas = ExtResource( 1 )
region = Rect2( 0, 480, 160, 240 )
[sub_resource type="AtlasTexture" id=7]
atlas = ExtResource( 1 )
region = Rect2( 0, 720, 160, 240 )
[sub_resource type="AtlasTexture" id=2]
atlas = ExtResource( 1 )
region = Rect2( 320, 0, 160, 240 )
[sub_resource type="AtlasTexture" id=8]
atlas = ExtResource( 1 )
region = Rect2( 320, 240, 160, 240 )
[sub_resource type="AtlasTexture" id=9]
atlas = ExtResource( 1 )
region = Rect2( 320, 480, 160, 240 )
[sub_resource type="AtlasTexture" id=10]
atlas = ExtResource( 1 )
region = Rect2( 320, 720, 160, 240 )
[sub_resource type="AtlasTexture" id=3]
atlas = ExtResource( 1 )
region = Rect2( 160, 0, 160, 240 )
[sub_resource type="AtlasTexture" id=11]
atlas = ExtResource( 1 )
region = Rect2( 160, 240, 160, 240 )
[sub_resource type="AtlasTexture" id=12]
atlas = ExtResource( 1 )
region = Rect2( 160, 480, 160, 240 )
[sub_resource type="AtlasTexture" id=13]
atlas = ExtResource( 1 )
region = Rect2( 160, 720, 160, 240 )
[sub_resource type="AtlasTexture" id=4]
atlas = ExtResource( 1 )
region = Rect2( 480, 0, 160, 240 )
[sub_resource type="AtlasTexture" id=14]
atlas = ExtResource( 1 )
region = Rect2( 480, 240, 160, 240 )
[sub_resource type="AtlasTexture" id=15]
atlas = ExtResource( 1 )
region = Rect2( 480, 480, 160, 240 )
[sub_resource type="AtlasTexture" id=16]
atlas = ExtResource( 1 )
region = Rect2( 480, 720, 160, 240 )
[resource]
animations = [ {
"frames": [ SubResource( 1 ) ],
"frames": [ SubResource( 1 ), SubResource( 5 ), SubResource( 6 ), SubResource( 7 ) ],
"loop": true,
"name": "left",
"speed": 5.0
}, {
"frames": [ SubResource( 2 ) ],
"frames": [ SubResource( 2 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ) ],
"loop": true,
"name": "right",
"speed": 5.0
}, {
"frames": [ SubResource( 3 ) ],
"frames": [ SubResource( 3 ), SubResource( 11 ), SubResource( 12 ), SubResource( 13 ) ],
"loop": true,
"name": "front",
"speed": 5.0
}, {
"frames": [ SubResource( 4 ) ],
"frames": [ SubResource( 4 ), SubResource( 14 ), SubResource( 15 ), SubResource( 16 ) ],
"loop": true,
"name": "back",
"speed": 5.0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 20 KiB