水平镜像 SKSpriteNode 纹理 [英] Horizontally mirror a SKSpriteNode texture

查看:12
本文介绍了水平镜像 SKSpriteNode 纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用名为 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;

但是要小心你可能会失去一些physicsbody的属性,我强烈建议你以这种方式使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆