ios - 我是否需要为每个新的 .swift 文件创建一个新的 SpriteKit 关卡编辑器文件?

标签 ios sprite-kit

我正在尝试熟悉 Sprite Kit 关卡编辑器。默认情况下,有一个“gamescene.sks”文件附加到“gamescene.swift”。

例如,如果我正在制作“gameoverscene”或“playscene”,如果我想在关卡编辑器中使用我的游戏,是否需要同时创建它们(.swift 和 .sks)?

此外,我对它的大小管理很感兴趣。我正在制作一款通用设备游戏。我应该更改它的默认大小(1024x768)还是不打扰?

此外,场景 Canvas 看起来是水平的,如果我的游戏仅是纵向模式,我应该更改它吗?

最佳答案

简短回答。是的。

原因..

每次您想要呈现或加载 .sks 文件时,您都需要使用这样的类加载它

let doors = SKTransition.doorwayWithDuration(1.0)
        let archeryScene = GameScene(fileNamed: "GameScene")
        self.view?.presentScene(archeryScene, transition: doors)

如果您查看常量,则会加载带有类的文件

MyScene(fileNamed: "MyScene")

所以,是的,每个 .sks 文件确实需要一个 .swift 文件。

有关 .sks 文件的更多信息,请参见此处。

Techotopia - An iOS 8 Swift Sprite Kit Level Editor Game Tutorial

此外,当我使用 Spritekit 关卡编辑器时,我通常将场景尺寸设置为 960 x 640 以支持最小的 iPhone。只要您有 @1x、@2x、@3x 以及可能的 @1x~iPad@2x~iPad,一切都会好起来的。只是为了确保在 ViewDidLoadinitWithSize(CGSize) 中添加 self.scaleMode = .AspectFill. 您可以将其设置为任何可能是的。您的选择是,

SKSceneScaleMode.Fill

Each axis of the scene is scaled independently so that each axis in the scene exactly maps to the length of that axis in the view.

SKSceneScaleMode.ResizeFill

The scene is not scaled to match the view. Instead, the scene is automatically resized so that its dimensions always matches those of the view.

SKSceneScaleMode.AspectFit

The scaling factor of each dimension is calculated and the smaller of the two is chosen. Each axis of the scene is scaled by the same scaling factor. This guarantees that the entire scene is visible, but may require letterboxing in the view.

SKSceneScaleMode.AspectFill

The scaling factor of each dimension is calculated and the larger of the two is chosen. Each axis of the scene is scaled by the same scaling factor. This guarantees that the entire area of the view is filled, but may cause parts of the scene to be cropped.

(感谢@epicbyte - Dealing with different iOS device resolutions in SpriteKit)

关于ios - 我是否需要为每个新的 .swift 文件创建一个新的 SpriteKit 关卡编辑器文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29009957/

相关文章:

swift - SKSpriteNode 不适用于随机数数组

ios - Q - 在 iOS 9 的最新 SDK 中查找与 FBAppCall 等效的类

ios - 使用设备倾斜快速移动 SKPhysicsBody

ios - 跨多个场景移动 SKSpriteNode 位置

swift - 从屏幕中间生成

ios - SpriteKit中的加速度计不起作用

ios - KeychainWrapperItem 在 iOS 7.1 中停止工作

ios - 将按钮添加到 UINavigationBar 的子类

ios - 使用图像作为带有 Storyboard 的静态表格 View 的背景

ios - 如何在 swift (SpriteKit) 中绘制作为单个节点的圆点