水平镜像SKSpriteNode纹理 [英] Horizontally mirror a SKSpriteNode texture
问题描述
我正在使用名为Sprite Kit的新API开发iOS7游戏。我想水平旋转SKSpriteNode图像/纹理。我试过它首先镜像图像,然后创建一个SKTexture,最后将它应用到SKSpriteNode,但它不起作用。有办法做到这一点吗?或者我应该有不同的图像?
I'm developing an iOS7 game with the new API called Sprite Kit. I'd like to horizontally rotated a SKSpriteNode image/texture. I've tried it by first mirroring the image, then creating a SKTexture and finally applying it to the SKSpriteNode but it doesn't work. Is there some way to do this? Or I should have to different images?
推荐答案
您可以使用此代码在x轴之间翻转:
You can use this code to flip among x-axis:
spriteNode.xScale = spriteNode.xScale * -1;
但请注意,你可能会失去一些物理学家的财产,我强烈建议你以这种方式使用xScale :
but be careful you can lose some of physicsbody's property, I highly suggest u to use xScale in this way:
spriteNodeBody = [SKNode node];
spriteNodeBody.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:spriteNode.size];
spriteNodeBody.physicsBody.categoryBitMask = CNPhysicsCategoryPlayer;
spriteNodeBody.physicsBody.collisionBitMask = CNPhysicsCategoryBall;
[spriteNodeBody addChild:spriteNode];
[self addChild:spriteNodeBody];
现在你可以安全地使用:
And now you can safely use:
spriteNode.xScale = spriteNode.xScale * -1;
这篇关于水平镜像SKSpriteNode纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!