Skip to content

Commit

Permalink
Update tweens to new API
Browse files Browse the repository at this point in the history
Modify FloatingText tweens slightly
  • Loading branch information
Kvel2D committed Mar 5, 2023
1 parent 74ae4aa commit e6a888a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 53 deletions.
72 changes: 33 additions & 39 deletions Scenes/FloatingText.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,36 @@ extends Node2D

# TODO: update to new tween API

#@onready var tween: Tween = $Tween
#@onready var label: Label = $Label
#
#var text: String = "placeholder"
#var duration: float = 1.0
#var color: Color = Color.WHITE
#
#
#func _ready():
# label.text = text
# modulate = color
#
## Text pops out at the start
# tween.interpolate_property(self, "scale",
# Vector2(0, 0),
# Vector2(1.0, 1.0),
# 0.3 * duration, Tween.TRANS_QUART, Tween.EASE_OUT)
#
## Text fades to transparent after popping out
# tween.interpolate_property(self, "modulate",
# color,
# Color(color.r, color.g, color.b, 0),
# 0.3 * duration, Tween.TRANS_LINEAR, Tween.EASE_OUT, 0.7 * duration)
#
## Text shrinks while fading
# tween.interpolate_property(self, "scale",
# Vector2(1.0, 1.0),
# Vector2(0.4, 0.4),
# 1.0 * duration, Tween.TRANS_LINEAR, Tween.EASE_OUT, 0.6 * duration)
#
## Text bounces
# tween.interpolate_property(self, "position",
# Vector2(0, 0),
# Vector2(50, -50),
# 1.0 * duration, Tween.TRANS_SINE, Tween.EASE_OUT)
#
# tween.interpolate_callback(self, 1.0 * duration, "queue_free")
#
# tween.start()
@onready var label: Label = $Label
var text: String = "placeholder"
var duration: float = 1.0
var color: Color = Color.WHITE

func _ready():
label.text = text
modulate = color

# Text bounces up and right
var pos_tween = create_tween()
pos_tween.tween_property(self, "position",
Vector2(50, -50),
1.0 * duration).set_trans(Tween.TRANS_SINE)

# Text pops out of nothing then shrinks
var scale_tween = create_tween()
scale = Vector2(0, 0)
scale_tween.tween_property(self, "scale",
Vector2(1.0, 1.0),
0.3 * duration).set_trans(Tween.TRANS_QUART)
scale_tween.tween_property(self, "scale",
Vector2(0.4, 0.4),
0.7 * duration).set_trans(Tween.TRANS_LINEAR)

# Text fades away to nothing at the end
var modulate_tween = create_tween()
modulate_tween.tween_property(self, "modulate",
Color(modulate.r, modulate.g, modulate.b, 0),
0.3 * duration).set_trans(Tween.TRANS_LINEAR).set_delay(0.7 * duration)

var queue_free_tween = create_tween()
queue_free_tween.tween_callback(queue_free).set_delay(1.0)
3 changes: 1 addition & 2 deletions Scenes/FloatingText.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://b6jet2t80ftgv"]
[gd_scene load_steps=2 format=3 uid="uid://vgeirnu7ramn"]

[ext_resource type="Script" path="res://Scenes/FloatingText.gd" id="2"]

[node name="FloatingText" type="Node2D"]
scale = Vector2(1e-05, 1e-05)
script = ExtResource("2")

[node name="Label" type="Label" parent="."]
Expand Down
27 changes: 15 additions & 12 deletions Scenes/Mobs/Mob.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const MOVE_SPEED_MIN: float = 100.0
const MOVE_SPEED_MAX: float = 500.0
const DEFAULT_MOVE_SPEED: float = MOVE_SPEED_MAX
const SELECTION_SIZE: int = 64
const HEIGHT_TWEEN_FAST_FORWARD_DELTA: float = 100.0

var _path_curve: Curve2D
var _current_path_index: int = 0
var _size: int = Unit.MobSize.NORMAL
var _category: int = Unit.MobCategory.HUMANOID
var movement_enabled: bool = true
var _facing_angle: float = 0.0
var _height_tween: Tween = null


@onready var _visual = $Visual
Expand Down Expand Up @@ -103,22 +105,23 @@ func on_damaged(_event: Event):
_health_bar.set_as_ratio(_health / MOB_HEALTH_MAX)


# TODO: update to new tween API
func adjust_height(height: float, speed: float):
pass
# if _height_tween.is_active():
# var tween_runtime: float = _height_tween.get_runtime()
# _height_tween.seek(tween_runtime)
# _height_tween.remove_all()
# If a tween is already running, complete it instantly
# before starting new one.
if _height_tween != null:
if _height_tween.is_running():
_height_tween.custom_step(HEIGHT_TWEEN_FAST_FORWARD_DELTA)

# var duration: float = abs(height / speed)
_height_tween.kill()
_height_tween = null

# _height_tween.interpolate_property(_visual, "position",
# _visual.position,
# Vector2(_visual.position.x, _visual.position.y - height),
# duration, Tween.TRANS_LINEAR, Tween.EASE_OUT)
_height_tween = create_tween()

# _height_tween.start()
var duration: float = abs(height / speed)

_height_tween.tween_property(_visual, "position",
Vector2(_visual.position.x, _visual.position.y - height),
duration).set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_OUT)


func _get_mob_animation() -> String:
Expand Down

0 comments on commit e6a888a

Please sign in to comment.