我有一个SKNode(),它有SKCropNode()子项。我可以运行所有类型的动作来旋转和缩放我的SKNode(),但是当我想使用任何类型的渐弱动作时,结果总是为alpha 1或alpha 0.没有办法褪色。
通过用SKShapeNode()替换SKCropNode(),淡入淡出动作正常。
谁能告诉我为什么?是不是可以淡化蒙面节点?
import SpriteKit
class GameScene: SKScene {
let player = SKNode()
let playerSize = CGFloat(50)
let playerCrop = SKCropNode()
let playerMask = SKSpriteNode(color: SKColor.blackColor(), size: CGSizeMake(CGFloat(100), CGFloat(100)))
let playerCircle = SKShapeNode(circleOfRadius: CGFloat(100))
let playerCenterMask = SKShapeNode(circleOfRadius: CGFloat(100))
let playerCenterCrop = SKCropNode()
override func didMoveToView(view: SKView) {
backgroundColor = SKColor.blackColor()
player.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
player.alpha = 0
addChild(player)
playerCenterMask.lineWidth = 20
playerCenterCrop.maskNode = playerCenterMask
playerMask.position.x = -playerSize
playerMask.position.y = playerSize
playerCircle.lineWidth = 0
playerCircle.fillColor = SKColor.redColor()
playerCrop.addChild(playerCircle)
playerCrop.maskNode = playerMask
playerCenterCrop.addChild(playerCrop)
player.addChild(playerCenterCrop)
// Animations
let playerScale = SKAction.scaleTo(2.0, duration: 5)
let playerFadeIn = SKAction.fadeInWithDuration(5)
let playerAnimation = SKAction.group([playerScale,playerFadeIn])
player.runAction(playerAnimation, completion: {})
}
}
答案 0 :(得分:1)
如评论中所述:
SKCropNode
使用alpha< 0.5不画。 > = 0.5来绘制,并且您无法设置混合模式,因此它可能正在执行源混合模式。这意味着它会覆盖alpha。孩子们后来混合。
创建播放器上下文,它以给定的alpha绘制,然后绘制SKCropNode
,覆盖alpha而不是混合。
对您的孩子而不是您的父母执行淡入淡出操作以获得您要查找的结果。
以下是您的来源与更改的相似之处:
import SpriteKit
class GameScene: SKScene {
let player = SKNode()
let playerSize = CGFloat(50)
let playerCrop = SKCropNode()
let playerMask = SKSpriteNode(color: SKColor.blackColor(), size: CGSizeMake(CGFloat(100), CGFloat(100)))
let playerCircle = SKShapeNode(circleOfRadius: CGFloat(100))
let playerCenterMask = SKShapeNode(circleOfRadius: CGFloat(100))
let playerCenterCrop = SKCropNode()
override func didMoveToView(view: SKView) {
backgroundColor = SKColor.blackColor()
player.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
player.alpha = 1
addChild(player)
playerCircle.alpha = 0
playerCenterMask.lineWidth = 20
playerCenterCrop.maskNode = playerCenterMask
playerMask.position.x = -playerSize
playerMask.position.y = playerSize
playerCircle.lineWidth = 0
playerCircle.fillColor = SKColor.redColor()
playerCrop.addChild(playerCircle)
playerCrop.maskNode = playerMask
playerCenterCrop.addChild(playerCrop)
player.addChild(playerCenterCrop)
// Animations
let playerScale = SKAction.scaleTo(2.0, duration: 5)
let playerFadeIn = SKAction.fadeInWithDuration(5)
let playerAnimation = playerScale
player.runAction(playerAnimation, completion: {})
playerCircle.runAction(playerFadeIn, completion: {})
}
}