我想以编程方式更改在 iOS 中使用 SceneKit 渲染的对象的 Material 。但我想使用动画图像文件。 PNG 序列在 iOS 中非常适用于 UIImageViews 之类的东西——我如何将它们用作 SceneKit 中的 Material ?
像这样的东西不工作:
floor.firstMaterial.diffuse.contents = [UIImage animatedImageNamed:@"ANIMATION_" duration:6.0f];
谢谢!
最佳答案
有一个更简单的解决方案(或者至少我认为它更简单),但我无法证明它是否更有效。我已经在 iPad mini(第一代)上对此进行了测试,它运行良好。
与其将作为 spritesheet 的纹理放置到 Material 的内容中(并摆弄着色器),不如将 SKScene 对象放置在那里。
这样您就可以在 SKScene 中使用 SKSpriteNode 对象并使用 SCNAction 对象为它们设置动画。然后,无需接触着色器代码即可轻松且更强大地控制所有动画。
NSArray<SKTexture*> *cursorTextures =
@[
[SKTexture textureWithImageNamed:@"tilecursor1.png"],
[SKTexture textureWithImageNamed:@"tilecursor2.png"],
[SKTexture textureWithImageNamed:@"tilecursor3.png"],
[SKTexture textureWithImageNamed:@"tilecursor4.png"],
[SKTexture textureWithImageNamed:@"tilecursor5.png"]
];
SKSpriteNode *cursorSprite = [SKSpriteNode spriteNodeWithTexture:cursorTextures[0]];
cursorSprite.position = CGPointMake(cursorSprite.size.width/2.0, cursorSprite.size.height/2.0);
[cursorSprite runAction:[SKAction repeatActionForever:[SKAction animateWithTextures:cursorTextures timePerFrame:0.1]]];
SKScene *cursorScene = [SKScene sceneWithSize:cursorSprite.size];
cursorScene.backgroundColor = [UIColor clearColor];
[cursorScene addChild:cursorSprite];
...
self.cursor.material.diffuse.contents = cursorScene;
关于ios - 我可以使用 PNG 序列作为 SceneKit 对象上的动画 Material 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28200482/