我试图用纹理旋转一个SKShapeNode,但它不起作用。基本上,我有一个有纹理的圆圈,我试图用与SKSpriteNode相同的方式使它旋转:
let spin = SKAction.rotateByAngle(CGFloat(M_PI/4.0), duration: 1)问题是圆是旋转的,而不是纹理。我可以通过使用以下代码来检查这一点:
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))这是我创建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)请帮帮忙。提前感谢!
PS:我知道使用SKSpriteNode会更好,但是我的目标是在一个圆形的框架中放置一个方形的图像,我认为使用SKShapeNode将是完美的。如果有人知道如何创建循环SKSpriteNode,可以在“答案”部分随意发布!:)
这就是我想要达到的目标(具有旋转的能力):

发布于 2016-04-01 11:31:47
您可以通过使用SKCropNode并将其掩码属性设置为圆形纹理来实现您想要的结果:
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)
}假设蒙版图片的大小为300×300像素。在这种情况下,你用作掩码的圆圈必须有相同的大小。这意味着在图像编辑器中,圆圈本身的半径必须是150像素(直径300像素)。
掩码节点确定图片的可见区域。所以别弄得太大了。掩码节点必须是具有透明背景的完全不透明圆。
https://stackoverflow.com/questions/36337331
复制相似问题