ios - 告诉 iOS 不要调整 SKNode 动画纹理的大小?

标签 ios swift sprite-kit

我正在使用 Swift 为 iOS 编写游戏。

游戏正在使用纹理数组进行初始化。我在动画中使用这些纹理。

我每次创建一个不同大小的SKNode:

let node = SKSpriteNode(texture: nodeTextures[0])
node.size = size; //from func argument
node.runAction(SKAction.repeatActionForever
(SKAction.animateWithTextures
(nodeTextures, timePerFrame: 0.05, resize: false, restore: false)))

使用调整大小的纹理渲染的节点。

我可以以某种方式告诉 iOS 不要调整纹理大小吗?如果是的话,我可以以某种方式在 SKNode 中定义纹理的原点坐标吗?

最佳答案

使用纹理和动画创建一个子节点。调用node.addChild(textureNode) 使其成为子节点。然后在该子节点上运行该操作,该子节点将始终位于与 node 相同的位置,但不会更改 node 的大小。像这样的事情:

let node = SKSpriteNode()
node.size = size; //from func argument
// Create texture node to hold the texture
let textureNode = SKSpriteNode(texture: nodeTextures[0])
node.addChild(textureNode)
textureNode.runAction(SKAction.repeatActionForever
(SKAction.animateWithTextures
(nodeTextures, timePerFrame: 0.05, resize: false, restore: false)))

这允许您稍后调整节点的大小,而无需重新缩放textureNode中的图像。

关于ios - 告诉 iOS 不要调整 SKNode 动画纹理的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32161324/

相关文章:

ios - 如何在 Swift 中向后发送 UIView 元素

运行 flutter 升级后iOS模拟器性能不佳

swift - 函数返回太早

ios - 如何将 ScnNode 用作 ScnLight?

ios - 按钮上的 UITableViewCell 单击使用核心数据更新数据库属性值

ios - UIActivityViewController 或 UIDocumentInteractionController 与 WhatsApp 和 FB

swift 错误 : Binary operator == cannot be applied to type '_' and 'Int'

快速正确的语法 if else while etc

swift/Spritekit : Play music through specific scenes

ios - GameScene 尺寸比我的设备屏幕尺寸宽