SpriteKit 学习体会贴(不断完善中)

1. 关于 SKShapeNode

刚接触SpriteKit时,看到这个类,以为它会比SKSpriteNode更为轻量级,但其实不是:

Shape nodes are useful for content that cannot be easily decomposed into simple textured sprites. Shape nodes are also very useful for building and displaying debugging information on top of your game content. However, the SKSpriteNode class offers higher performance than this class, so use shape nodes sparingly.

其实是SKSpriteNode有更高的效率。

这里提到了SKShapeNode的使用场景:Shape nodes are useful for content that cannot be easily decomposed into simple textured sprites. 这句话怎么理解呢?

我们看一看官方文档用SKShapeNode实现的效果图:

上面这4附图,都是用ShapeNode绘制出来的。我是这样理解的,当你需要利用opengl函数绘制一些内容时,可以使用ShapeNode,否则应该使用SpriteNode。

2. SKLightNode

详细解释请参看原文,http://www.cocoachina.com/ios/20140811/9351.html

我这里将有关SKLightNode的内容摘抄一下:

下面我们看看 SKLightNode 的一些属性:
1. enabled 光源的开关
2. ambientColor 环境色,默认是黑色,也就是没有环境色。它无视自身的alpha以及SKLightNode的falloff属性和SKSpriteNode的normalTexture属性,分分钟照亮全场。 (这里的意思就是环境光的强弱不会根据光源的位置而变化,并且影响整个视图)
3. lightColor 顾名思义就是光的颜色,默认是白色。
4. shadowColor 被精灵物体遮挡产生的阴影颜色。
5. falloff 光源强度的衰减比率
6. categoryBitMask 光的种类,32位整型数。SKSpriteNode 的 lightingBitMask、shadowedBitMask 和 shadowCastBitMask 存储着光的种类,分别意味着:被何种光照亮、被何种光产生的阴影覆盖和遮挡何种光线并产生阴影。

这里比较难理解的是
shadowedBitMask,有如下官方解释
If the sprite is inside a shadow cast by a light and the sprite has a lower z position than the light, the shadow affects how the sprite is lit.
但是,我的实验结果是,一个sprite是否被阴影影响,是跟lightNode和这个spriteNode的zposition决定的,如果spriteNode的zposition低,那么这个其他物体投射阴影就会影响它,反之,则不会。和shadowedBitMask属性,没有什么关系,不知道哪里理解错了。。。


 这里有一个demo,非常好 https://github.com/ymc-thzi/iOS8-SKLightNode

原文地址:https://www.cnblogs.com/breezemist/p/6322299.html