【发布时间】:2022-12-14 11:26:25
【问题描述】:
我在 2 个位置之间摇摆我的角色:
空闲 -> 运行并向右移动 -> 空闲 -> 运行并向左移动 -> (重复)
extends Sprite
func _ready():
var tween = get_tree().create_tween().set_loops()
## Idle 1 ##
tween.tween_callback(animation_player,"play",["Idle"]) # plays idle animation
tween.tween_interval(2)
##
## Running 1 ##
tween.tween_callback(animation_player,"play",["Running"]) # starts running animation
tween.tween_property(self,"flip_h", false, 0)
tween.tween_property(self,"position:x", 500.0, 2) # move position to 1000
##
## Idle 2 ##
tween.tween_callback(animation_player,"play",["Idle"]) # plays idle animation
tween.tween_interval(2)
##
## Running 2 ##
tween.tween_callback(animation_player,"play",["Running"]) # starts running animation
tween.tween_property(self,"flip_h", true, 0)
tween.tween_property(self,"position:x", -500.0, 2) # move position to 1000
##
它工作正常但问题是我必须写两次 Idle & Run 段,这真的很烦人
我试过这个:
func _ready():
var tween = get_tree().create_tween().set_loops()
## Idle ##
tween.tween_callback(animation_player,"play",["Idle"]) # plays idle animation
tween.tween_interval(2) # pause for 2 seconds
##
## Running ##
tween.tween_callback(animation_player,"play",["Running"]) # starts running animation
tween.tween_property(self,"flip_h", !flip_h, 0)
tween.tween_property(self,"position:x", position.x*-1, 2) # move position to 1000
##
但似乎每次循环运行时传递的是变量的字面值而不是新值
有什么我想念的吗?还是没有解决方法?
【问题讨论】:
标签: animation godot gdscript tween