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?
If you're just trying to flip the sprite along an axis, you can do something like this:
sprite.xScale = -1.0;
You can use this code to flip among x-axis:
spriteNode.xScale = spriteNode.xScale * -1;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With