Jumping into SpriteKit

如果你对个人开发者还有一些念想的话,游戏领域可能是个人开发者值得投入精力尝试的。
比起应用来说,游戏没有涉及到那么多的资源如服务端,产品经理,交互。 如果是简单的样式可能美工方面自己现学就可以搞定了
我这里指的是一些简单的游戏,如单场景的消除类:

大体都是一些较为经典的个人开发者作品。盈利模式可以是:App收费,App接入市场广告,App道具收费

好了,下面进入正题。早些年做游戏的话,如果注重跨平台 你的选择可能就是 Cocos2d-X 了。 但其实Apple自身是有套游戏框架: SpriteKit

About SpriteKit

可以按照 Jumping into SpriteKit 这个章节熟悉一下 SpriteKit 。

Getting Started

这里要注意的是 第一步里面一定要将storyboard里面的ViewController 的view object class 设置为 SKView。

Open the storyboard for the project. It has a single view controller (SpriteViewController). Select the view controller’s view object and change its class to SKView.

SpriteKit内容都是绘制在SKView里面的,而SKView渲染出来的东西叫做 场景(scene)SKScene类型。 场景的交互是响应传递链的。

Using Actions to Animate Scenes

每个SKNode都有name属性作为他的描述,给节点起个名字方便你后面查找和指定节点执行动作。 类似UIKit里面的view.tag

SKAction 需要重点了解一下。

Transitioning Between Scenes

这个是区别于UIKit的,没有页面跳转的概念。这里指的 Scene A切换为Scene B。
使用SKTransition可以添加切换动画。查看SKTransition.h,SpriteKit还是自带了蛮多场景切换动画。

Creating Nodes That Interact with Each Other

这个是最有意思的地方: 可以添加SKNode physicsBody属性,让其有物理特性。
这里还提到了 didSimulatePhysics,实际上 SpriteKit中 Scene 是在实时重复绘制的。他的每一帧绘制包括了以下时机回调

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
Override this to perform per-frame game logic. Called exactly once per frame before any actions are evaluated and any physics are simulated.

@param currentTime the current time in the app. This must be monotonically increasing.
*/
- (void)update:(NSTimeInterval)currentTime;

/**
Override this to perform game logic. Called exactly once per frame after any actions have been evaluated but before any physics are simulated. Any additional actions applied is not evaluated until the next update.
*/
- (void)didEvaluateActions;

/**
Override this to perform game logic. Called exactly once per frame after any actions have been evaluated and any physics have been simulated. Any additional actions applied is not evaluated until the next update. Any changes to physics bodies is not simulated until the next update.
*/
- (void)didSimulatePhysics;

/**
Override this to perform game logic. Called exactly once per frame after any enabled constraints have been applied. Any additional actions applied is not evaluated until the next update. Any changes to physics bodies is not simulated until the next update. Any changes to constarints will not be applied until the next update.
*/
- (void)didApplyConstraints NS_AVAILABLE(10_10, 8_0);

/**
Override this to perform game logic. Called after all update logic has been completed. Any additional actions applied are not evaluated until the next update. Any changes to physics bodies are not simulated until the next update. Any changes to constarints will not be applied until the next update.

No futher update logic will be applied to the scene after this call. Any values set on nodes here will be used when the scene is rendered for the current frame.
*/
- (void)didFinishUpdate NS_AVAILABLE(10_10, 8_0);

update_loop

最后

来自 raywenderlich 的学习资料