将 .sks 连接到 skscene.h [英] Connect .sks to skscene.h

查看:22
本文介绍了将 .sks 连接到 skscene.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个 .sks Sprite Kit 场景文件,我可以在其中直观地放置对象(有点像 Sprite Kit 版本的界面构建器,对吧?).我还有一个 SKScene.h 头文件和 SKScene.m 文件,我可以在其中为 SKScene 编写代码.如何将 .sks 场景连接到 .h SKScene 标头?对不起,这太基本了,但我很难过.

So I have a .sks Sprite Kit Scene file in which I can visually place objects (somewhat like Sprite Kit's version of the interface builder right?). I also have an SKScene.h header and SKScene.m file where I can write code for an SKScene. How do I connect the .sks scene to the .h SKScene header? Sorry this is so basic but I am stumped.

推荐答案

我不使用 unarchiveFromFile 方法,因为我在现有的 SpriteKit 类结构中找不到它,而且我真的不需要写在上面我自己的.我找到了另一种使用它的方法,更简单,它在 XCode 7 中运行良好:
1. 我有 .sks 文件,其中的节点使用 UI 界面设计得很好.
2. 我还有与 .sks 文件同名的 .h 和 .m 文件.所以,如果我有 Scene1.sks,那么我也有 Scene1.h 和 Scene1.m 文件.
3.在Scene1.h中,我有代码表明它是一个SKScene:

I don't use unarchiveFromFile method, because I can't find it in the existing SpriteKit class structure, and I don't really need to write it on my own. I found another way to use it, much simpler, and it works fine in XCode 7:
1. I have the .sks file with the nodes inside it designed nicely using the UI interface.
2. I also have the .h and .m file with the same names as the .sks file. So, if I have Scene1.sks, then I also have Scene1.h and Scene1.m files.
3. In Scene1.h I have the code indicating that it is a SKScene:

@interface Scene1 : SKScene

在 Scene1.m 中,我只是使用这种方式与视觉添加的对象进行交互:

In Scene1.m I just use this way to interact with the visually added objects:

SKNode *heroPositionNode = [self childNodeWithName:@"hero"];

其中 heroPositionNode 是我想要使用的变量 - 此处或代码中的其他地方.英雄"是 .sks 中节点的名称 - 在 UI 设计器本身中.
4.在GameViewController中,我只用这个:

where heroPositionNode is my variable that I want to work with - here or elsewhere in my code. The "hero" is the name of node inside the .sks - in the UI designer itself.
4. In GameViewController, I just use this:

Scene1 *scene = [Scene1 nodeWithFileNamed:@"Scene1"];  
scene.scaleMode = SKSceneScaleModeAspectFill;
[skView presentScene:scene];

这行得通.似乎一切都是自动连接的.希望它有帮助,如果它也适用于您,请告诉我.

This just works. It seems that everything is connected automatically. Hope it helps, let me know if it works for you too.

这篇关于将 .sks 连接到 skscene.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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