基础使用
创建 Swf 节点
Swf 继承自 Node2D,可以在场景中直接添加:
加载 SWF 文件
通过检查器
- 选中
Swf 节点
- 在检查器找到
swf_resource 属性
- 加载一个
.swf 文件(模块自动解析并准备渲染)
通过代码
var swf = $Swf
swf.swf_resource = preload("res://my_animation.swf")
控制播放
播放/停止
# 播放(按资源中第一个角色)
swf.play_id(0)
# 通过角色 ID 播放
swf.play_id(character_id)
# 通过 SymbolClass 名称播放
swf.play_name("my_animation")
# 停止(保留在当前帧)
swf.stop()
# 从当前帧恢复
swf.resume()
# 彻底停止并回到第 0 帧
swf.reset()
帧控制
# 跳转到指定帧
swf.goto_frame(10)
# 跳转到指定帧并停止
swf.goto_frame(10, true)
# 跳转后父节点停止,子元件继续播放
swf.goto_frame(10, true, true)
# 按帧标签跳转
swf.goto_label("idle")
swf.goto_label("idle", true)
查询状态
var playing = swf.is_playing()
var frame = swf.get_current_frame()
var total = swf.get_frame_count()
信号
func _ready():
$Swf.animation_finished.connect(_on_finished)
$Swf.animation_looped.connect(_on_looped)
func _on_finished():
print("动画播放完成")
func _on_looped():
print("循环播放一轮完成")
属性调整
基本播放
| 属性 |
类型 |
说明 |
animation_id |
int |
0 |
animation_name |
String |
"" |
auto_play |
bool |
false |
loop |
bool |
是否循环 |
speed_scale |
float |
播放速度倍率 |
渲染
| 属性 |
类型 |
说明 |
render_target_size |
Vector2i |
渲染目标尺寸(加载时自动匹配帧大小) |
preview_enabled |
bool |
编辑器预览开关 |
变换
| 属性 |
类型 |
说明 |
root_position |
Vector2 |
根实例位置 |
root_rotation |
float |
根实例旋转(弧度) |
root_scale |
Vector2 |
根实例缩放 |
root_skew |
float |
根实例倾斜(弧度) |
支持的 SWF 特性
- DefineShape 1-4(形状定义)
- DefineSprite(精灵动画时间轴)
- PlaceObject 1-3 / RemoveObject 1-2(显示列表控制)
- DefineBitsJPEG / DefineBitsLossless / DefineBitsJPEG2-4(位图)
- ColorTransform(CXFORM 颜色变换)
- Filter 链(Glow / Blur / DropShadow / ColorMatrix)
- BlendMode(Add / Multiply / Screen / Subtract / Erase 等)
- MorphShape(变形形状插值渲染)
- Mask(stencil 方案,多层嵌套)
- SymbolClass 标签(名称→ID 映射)
- FrameLabel 标签(帧名称跳转)
不支持
- ❌ ActionScript / 按钮 / 交互
- ❌ 文本 / 字体(DefineText / DefineEditText)
- ❌ 音视频