gpt4 book ai didi

swift - 更改所有 SKTextures 的 SKTextureFilteringMode

转载 作者:行者123 更新时间:2023-11-28 12:28:16 24 4
gpt4 key购买 nike

有没有办法为所有 SKTexturesfilteringMode 属性分配给 SKTextureFilteringMode.nearest?除了单独分配给每个纹理。以下工作正常,但我宁愿不必遍历纹理,而只需为过滤模式设置默认值。这可能吗?

func walk () -> SKAction {

let walkTexture1 = SKTexture(imageNamed: "walk1.png")
let walkTexture2 = SKTexture(imageNamed: "walk2.png")
let walkTexture3 = SKTexture(imageNamed: "walk3.png")
let walkTexture4 = SKTexture(imageNamed: "walk4.png")
let walkTexture5 = SKTexture(imageNamed: "walk5.png")


let animationTextures: [SKTexture] = [walkTexture1, walkTexture2, walkTexture3, walkTexture4, walkTexture5]

for texture in animationTextures {
texture.filteringMode = SKTextureFilteringMode.nearest
}

let walkAnimation = SKAction.animate(with: animationTextures, timePerFrame: 0.3/5)

return walkAnimation

最佳答案

在同一个循环中创建纹理和设置属性

让纹理 = (1...5).map {
让 texture = SKTexture(imageNamed: "walk\($0).png")
texture.filteringMode = SKTextureFilteringMode.nearest
返回纹理
}

或者只使用 forEach

设置属性

textures.forEach {
$0.filteringMode = .nearest
}

关于swift - 更改所有 SKTextures 的 SKTextureFilteringMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42779919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com