如何在 sks 文件“SpriteKit action"中获取 Xcode 动作编辑器上的所有动作名称 [英] How to get all actions name on Xcode action editor in sks file "SpriteKit action"

查看:24
本文介绍了如何在 sks 文件“SpriteKit action"中获取 Xcode 动作编辑器上的所有动作名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SpriteKit 动作文件,里面有一些动作.

I've a SpriteKit action file with some actions inside.

要使用一个操作,我使用:

To use one action, I use:

let action = SKAction(named: "Shake")

相反可以直接使用 MyActions.sks 文件中的名称吗?类似于:

Instead is possible to use directly the name inside MyActions.sks file? Something like:

let actions = SKScene(fileNamed: "MyActions.sks")`  
let shakeAction = actions.listOfAction.Shake //this is my guess

如果我打印场景文件:

let actions = SKScene(fileNamed: "MyActions.sks")
print(actions)

输出为:

Optional({
    "_info" =     {
        "_previewScenePath" = "PippiPompiere/GameScene.sks";
    };
    actions =     {
        PlayerIdle1 = "<SKGroup: 0x79e60ec0>";
        PlayerMoveToHouse0 = "<SKGroup: 0x7b1ea010>";
        PlayerMoveToHouse1 = "<SKGroup: 0x7b052cd0>";
        PlayerMoveToHouse2 = "<SKGroup: 0x7b1ebbd0>";
        Rotate360 = "<SKGroup: 0x79e61710>";
        Shake = "<SKGroup: 0x79e60a10>";
        SunShake = "<SKGroup: 0x7b1e8620>";
        WaterJet = "<SKGroup: 0x7b1e8ce0>";
    };
})
(lldb) 

可以有像数组这样的动作吗?

is possible to have actions like an array?

谢谢

推荐答案

AFAIK,您可以从 .sks 文件中获取 actions 字典.在这里,我有一个 MyCustomActions.sks 文件,其中包含一个操作 Pulse.

AFAIK, you can get the actions dictionary from the .sks file. Here, I have a MyCustomActions.sks file with an action Pulse.

guard
    let node = SKNode(fileNamed: "MyCustomActions"),
    let actions = node.value(forKey: "actions") as? [String:SKAction],
    let pulse = actions["Pulse"]
else { return }

print(pulse.duration)  // 0.6 seconds

从这里,您可以从 actions 字典中实现自己的 struct.

From here, you can implement your own struct from the actions dictionary.

要获取所有操作的名称,

To get all the name of actions,

let actionNames = actions.map { $0.key }  // ["Pulse"]

这篇关于如何在 sks 文件“SpriteKit action"中获取 Xcode 动作编辑器上的所有动作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆