SpriteKit. Stop rotate Texture with CameraNode

无人久伴 提交于 2019-12-05 22:52:25

The reason for this is that shape-fills are done in screen-space. The texture is not mapped onto the SKShapeNode with texture coordinates, it is treated just like a fill colour.

The solution is to use an SKSpriteNode or an SKCropNode. If you use the sprite node, your image would have transparency around the edges already, to get the circular shape of the planet. If you use the crop node, you can add a square sprite node as a child, then set its mask node property to your shape node - this will determine the masked portions that get rendered.

The crop node method would be something like this:

planetTexture = SKTexture(imageNamed: "asanoha")
planetSprite = SKSpriteNode(texture: planetTexture)
planetMask = SKShapeNode(path: beizerPath.cgPath)
planetMask.fillColor = UIColor.white
planet = SKCropNode()
planet.maskNode = planetMask
planet.addChild(planetSprite)
sceneNode.addChild(planet)

Update: I just watched your video and realised my answer made some incorrect assumptions about the look. However, the crop-node approach is still sound, just that you would need to set up the sprite node a bit differently, so that the texture repeats. The pure sprite with transparency wouldn't work for such a huge and irregular (and presumably generated) planet.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!