Node2D を継承する再生用ノードです。
リソースとアニメーションを指定して再生を行います。
@onready var ssnode: SpriteStudioPlayer2D = $target
func _ready() -> void:
# .ssab を読み込んでリソースを指定
var ssab: SSABResource = ResourceLoader.load("res://ssab_generated/Sample.ssab")
ssnode.set_ssab_resource(ssab)
# アニメーション名を指定
ssnode.set_animation("anime_1")
# 再生
ssnode.set_loop_count(-1) # -1 で無限ループ
ssnode.set_speed_scale(1.0)
ssnode.play()set_ssab_resource(res: SSABResource)/get_ssab_resource() -> SSABResourceset_animation(name: String)/get_animation() -> Stringset_autoplay(autoplay: bool)/is_autoplay() -> bool: シーン開始時に自動再生するかどうか。set_offset(offset: Vector2)/get_offset() -> Vector2: Node2D の原点を動かさずに描画位置だけをずらします。set_flip_h(flip: bool)/is_flipped_h() -> bool: 水平反転。set_flip_v(flip: bool)/is_flipped_v() -> bool: 垂直反転。set_animation_process_mode(mode: int)/get_animation_process_mode() -> int:0で Physics (_physics_process) 同期、1で Idle (_process) 同期。- エディタ内プレビュー: ノードを選択すると表示される SpriteStudio ボトムパネル(再生 / 一時停止 / 停止 / フレームスクラバ)でゲームを実行せずにプレビューできます。(旧
editor_playingインスペクタトグルはこのパネルに置き換えられました。) play(start_frame: float = -1.0): 再生を開始します。-1.0を指定した場合は、現在のフレームまたは区間の先頭から再生します。pause(): 再生を一時停止します。stop(): 再生を停止します。is_playing() -> bool/is_pausing() -> boolset_frame(frame: float)/get_frame() -> float/get_total_frames() -> intset_speed_scale(speed_scale: float)/get_speed_scale() -> floatset_frame_rate(fps: int)/get_frame_rate() -> intset_animation_section(start: int, end: int): 再生するフレーム区間を限定します。set_playback_direction(direction: int, style: int): 再生方向と再生スタイルを指定します。値の意味は下表を参照してください。set_loop_count(count: int)/get_loop_count() -> int:-1で無限ループ、0で1回だけ再生、nでn回繰り返し。set_frame_skip_enabled(enabled: bool)/is_frame_skip_enabled() -> bool(デフォルト:true)set_sub_frame_enabled(enabled: bool)/is_sub_frame_enabled() -> bool(デフォルト:false)set_cellmap_texture(cellmap_name: String, texture: Texture2D)/get_cellmap_texture(cellmap_name: String) -> Texture2D
| 引数 | 値 | 意味 |
|---|---|---|
direction |
0 |
順再生 (Forward) |
direction |
1 |
逆再生 (Backward) |
style |
0 |
通常 / 片道 (Normal) |
style |
1 |
往復再生 (PingPong) |
| シグナル | 引数 | 発行タイミング |
|---|---|---|
animation_started |
anim_name: String |
再生が開始された時 |
animation_changed |
anim_name: String |
アニメーションが切り替わった時 |
animation_finished |
anim_name: String |
再生が終了した時(非ループ時のみ) |
animation_looped |
anim_name: String |
ループして先頭に戻った時 |
user_data |
payload: Dictionary |
タイムライン上の「ユーザーデータ」キーに到達した時 |
signal_emitted |
command: String, value: Dictionary |
タイムライン上の「シグナル」キーに到達した時 |
SpriteStudio 上でユーザーデータに設定した値が Dictionary として渡されます。設定された項目のみ キーが含まれます(未設定の項目はキーごと存在しません)。
| キー | 型 | 内容 |
|---|---|---|
integer |
int |
整数値 |
point |
Vector2 |
座標値 |
rect |
Rect2 |
矩形値(x, y, width, height) |
string |
String |
文字列値 |
タイムライン上の「シグナル」に設定したパラメータが Dictionary として渡されます。パラメータ ID をキーに、各値(bool / int / float / String 等)が格納されます。command 引数にはシグナル名(command_id)が入ります。
Note
引数の正確な型・最新の取り得る値は実装 ss_player/ss_player_node_2d.h / ss_player/ss_internal_player.cpp を併せて参照してください。
frame プロパティはアニメート可能なので、AnimationPlayer のタイムライン(音・メソッド呼び出し・他ノードなど他トラック)と同期させて SpriteStudio アニメをスクラブできます。
SpriteStudioPlayer2Dに通常どおりSSAB Resourceを割り当て、Animationを選択。AnimationPlayerで、ノードのframeプロパティを対象に プロパティトラック を追加。frameを時間に沿ってキーフレーム(例:尺に合わせて0→ 最終フレーム)。frameは float なので補間されます。AnimationPlayerを再生。
Important
AnimationPlayer が frame を駆動している間は、ノードを自走させないでください(Autoplay をオフにし、play() も呼ばない)。さもないとノード自身の再生とキーフレームの frame が毎フレーム競合します。
これ以上の準備は不要です。キー値は AnimationPlayer のアニメーション側に保存され(ノードの frame はシーンに保存されません)、同じトラックがランタイムでも再生を駆動します。