【发布时间】:2018-01-14 11:55:43
【问题描述】:
我正在使用 SKMutableTexture 在游戏中渲染可破坏的地面。出于所有意图和目的,这很好用,除非我想将透明像素渲染到 MutableTexture 中已经存在非透明像素的位置。
我已经为 RGBAColor 创建了一个结构,如下所示:
struct RGBAColor {
var r: UInt8
var g: UInt8
var b: UInt8
var a: UInt8
static var clear = RGBAColor(r: 0, g: 0, b: 0, a: 0)
}
然后我像这样修改 SKMutableTexture:
self.texture.modifyPixelData({ (voidptr, len) in
let bytes = voidptr!.assumingMemoryBound(to: RGBAColor.self)
for (index, color) in self.modifiedPixels {
bytes[index] = color
self.pixels[index] = color
}
})
.. 其中“modifiedPixels”是一个类似于 [Int : RGBAColor] 的字典(为了不更新纹理中的所有像素 - 仅更新修改的像素。
当颜色具有 alpha (a) > 0 时,它可以按我的意图工作。但当它为 0 时则不行(就像像素是在现有纹理之上渲染的......而不是像您正在修改实际像素数据)。
我做错了吗?或者这是预期的行为?
【问题讨论】:
标签: swift sprite-kit sktexture