Editor创建的项目的SKSpriteNode

Editor创建的项目的SKSpriteNode

本文介绍了如何获得通过SpriteKit Editor创建的项目的SKSpriteNode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用SpriteKit(带有Objective-C)在XCode中创建了一个相当简单的(现在是实验性的)游戏".

I have created a fairly simple (at this point, experimental) "game" in XCode using SpriteKit (with Objective-C).

我知道如何手动创建一个SKSpriteNode对象并将其添加到SKScene中-但我正在尝试做相反的事情-在该对象中,我在XCode SceneKit GUI自身内部创建了Sprite(并为其命名),现在我想在代码中 retriive .

I know how to manually create a SKSpriteNode object and add it to the SKScene - but I am kind of trying to do the opposite - where I created the sprite inside the XCode SceneKit GUI itself (and gave it a name), now I want to retreive it in my code.

在使用XCode的先前经验中,您可以通过声明@property UIOutlet [etc],然后将其作为IB/Storyboard UI内部的参考插座进行连接来进行此操作-但我找不到在内部执行此操作的任何类似方法SpriteKit用户界面.

In prior experience with XCode, you would do this by declaring a @property UIOutlet [etc] and then connecting it as a referencing outlet inside the IB/Storyboard UI - but I can't find any similar way to do that inside the SpriteKit UI.

我可以创建一个属性(作为SKSpriteNode),并将其命名为与SpriteKit对象相同的名称-并且它显示在SKScene下(在调试器中),但是为"nil"-即未与我在XCode SpriteKit UI中创建的对象.

I can create a property (as an SKSpriteNode), and name it the same as my SpriteKit object - and it shows up under the SKScene (in the debugger), but is "nil" - i.e. is not "associated" with the object I created in the XCode SpriteKit UI.

我是否缺少某些东西-或这样做完全错误?:-O

Am I missing something - or doing this completely wrong? :-O

推荐答案

如果在Sprite Kit编辑器中设置了节点的name属性,则可以通过以下方式在Swift中访问该节点:

If you set the name property of a node in the Sprite Kit Editor, you can access the node, in Swift, by

if let node = self.childNodeWithName("NodeName") as? SKSpriteNode {
    // Set up your sprite here
}

SKSpriteNode *node = (SKSpriteNode *)[self childNodeWithName:@"NodeName"];

在Obj-C中.

这篇关于如何获得通过SpriteKit Editor创建的项目的SKSpriteNode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:16