使用纹理旋转 SKShapeNode

Ant*_* O. 5 rotation sprite-kit skshapenode swift

我试图用SKShapeNode纹理旋转,但它不起作用。基本上,我有一个带有纹理的圆圈,我试图使用与以下操作相同的方式使其旋转SKSpriteNode

let spin = SKAction.rotateByAngle(CGFloat(M_PI/4.0), duration: 1)
Run Code Online (Sandbox Code Playgroud)

问题是圆圈在旋转,但纹理没有旋转。我可以使用以下代码检查这一点:

let wait = SKAction.waitForDuration(0.5)
let block = SKAction.runBlock({
                     print(self.circle.zRotation)  
                     })
let sequence = SKAction.sequence([wait, block])
self.runAction(SKAction.repeatActionForever(sequence))
Run Code Online (Sandbox Code Playgroud)

这是我用于创建的代码SKShapeNode

let tex:SKTexture = SKTexture(image: image)
let circle = SKShapeNode(circleOfRadius: 100 )
circle.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 + 200)
circle.strokeColor = SKColor.clearColor()
circle.glowWidth = 1.0
circle.fillColor = SKColor.whiteColor()
circle.fillTexture = tex
self.addChild(circle)
// Runing the action
circle.runAction(spin)
Run Code Online (Sandbox Code Playgroud)

请帮忙。提前致谢!

PS:我知道使用 anSKSpriteNode会更好,但我的目标是将方形图像放置在圆形框架中,我认为使用 anSKShapeNode会是完美的。如果有人知道如何创建通告SKSpriteNode,请随时将其发布在答案部分!:)

这就是我想要实现的目标(具有旋转它的能力): 在此输入图像描述

Whi*_*ind 2

您可以通过使用 SKCropNode 并将其 mask 属性设置为圆形纹理来实现您想要的效果:

override func didMoveToView(view: SKView) {

     let maskShapeTexture = SKTexture(imageNamed: "circle")

     let texture = SKTexture(imageNamed: "pictureToMask")

     let pictureToMask = SKSpriteNode(texture: texture, size: texture.size())

     let mask = SKSpriteNode(texture: maskShapeTexture) //make a circular mask

     let cropNode = SKCropNode()
     cropNode.maskNode = mask
     cropNode.addChild(pictureToMask)
     cropNode.position = CGPoint(x: frame.midX, y: frame.midY)
     addChild(cropNode)
}
Run Code Online (Sandbox Code Playgroud)

假设要遮罩的图片的大小为 300x300 像素。在这种情况下,用作遮罩的圆圈必须具有相同的大小。意味着在图像编辑器中制作时,圆本身的半径必须为 150 像素(直径为 300 像素)。

Mask节点决定了图片的可见区域。所以不要让它太大。遮罩节点必须是具有透明背景的完全不透明的圆圈。