首先:我知道,这个问题在这里已经有很多答案,但它们并没有帮助我解决这个问题。
我编写了一个小游戏。第一次启动时有一个小教程,其中逐步解释了游戏的每个元素。在每一步中,我都想强调其中一个要素。所以我在元素前面放置了一个 alpha 为 0.9 的黑色 SKSpriteNode。如果要突出显示某个元素,则 SpriteNode 此时应变为透明。所以我制作了一个 SKCropNode 和一个遮罩,如下面的代码所示(我只向您展示了基本部分):
import SpriteKit
class FirstLaunch: SKScene {
var fullScreen:SKSpriteNode!
var mask:SKSpriteNode!
var circle1:SKShapeNode!
var circle2:SKShapeNode!
var crop:SKCropNode!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize) {
super.init(size: size)
fullScreen = SKSpriteNode(color: .black, size: self.size)
fullScreen.anchorPoint = .zero
fullScreen.position = .zero
fullScreen.alpha = 0.9
mask = SKSpriteNode(color: .white, size: self.size)
mask.anchorPoint = .zero
mask.position = .zero
mask.alpha = 1
circle1 = SKShapeNode(circleOfRadius: 55)
circle1.fillColor = .white
circle1.lineWidth = 0
circle1.alpha = 1
circle1.blendMode = .subtract
//spaceship is one of my elements, which have to be highlighted at some point
circle1.position = spaceship.position
mask.addChild(circle1)
//At one point I need two highlights at the same time
circle2 = SKShapeNode(circleOfRadius: 55)
circle2.fillColor = .white
circle2.lineWidth = 0
circle2.alpha = 1
circle2.blendMode = .subtract
crop = SKCropNode()
crop.maskNode = mask
crop.addChild(fullScreen)
addChild(crop)
}
}
我在这里找到了这个解决方案:https://stackoverflow.com/a/40710050/8162321 https://stackoverflow.com/a/40710050/8162321我在不同的设备和模拟器上测试了它。我的问题是,它在 Xcode 8 和 Xcode 9 Beta 的模拟器中都能完美运行,但在装有 iOS 10.3.3 的 iPhone 和装有 iOS 11 Beta 的 iPhone 上都无法运行。在 iPhone 上,除了亮点之外,整个应用程序运行得非常完美。
Images:
模拟器上的一个教程点 https://i.stack.imgur.com/5zeMZ.png
iPhone 上也一样 https://i.stack.imgur.com/pC8ew.png
你能告诉我为什么不一样吗?我以前从未见过这样的事情。
我也有同样的问题。我花了三个星期才找到答案。
将孔的 alpha 设置为 0.001,并将混合模式设置为 .replace。
然后它将在设备上运行(对我来说是 iOS 12)。
import SpriteKit
class FirstLaunch: SKScene {
var fullScreen:SKSpriteNode!
var mask:SKSpriteNode!
var circle1:SKShapeNode!
var circle2:SKShapeNode!
var crop:SKCropNode!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize) {
super.init(size: size)
fullScreen = SKSpriteNode(color: .black, size: self.size)
fullScreen.anchorPoint = .zero
fullScreen.position = .zero
fullScreen.alpha = 0.9
mask = SKSpriteNode(color: .white, size: self.size)
mask.anchorPoint = .zero
mask.position = .zero
mask.alpha = 1
circle1 = SKShapeNode(circleOfRadius: 55)
circle1.fillColor = .white
circle1.lineWidth = 0
// Here is the required change
circle1.alpha = 0.001
circle1.blendMode = .replace
//spaceship is one of my elements, which have to be highlighted at some point
circle1.position = spaceship.position
mask.addChild(circle1)
crop = SKCropNode()
crop.maskNode = mask
crop.addChild(fullScreen)
addChild(crop)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)