我正在做一个游戏,我在旋转一个精灵节点时遇到了麻烦,这是我拥有的代码;我必须添加什么才能将它旋转,比如说45度?
SKSpriteNode *platform = [SKSpriteNode spriteNodeWithImageNamed:@"YellowPlatform.png"];
platform.position = CGPointMake(CGRectGetMidX(self.frame), -200+CGRectGetMidY(self.frame));
platform.size = CGSizeMake(180, 10);
platform.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:platform.size];
platform.physicsBody.dynamic = NO;
[self addChild:platform];
发布于 2013-10-16 16:28:57
您可以为旋转创建SKAction,然后在节点上运行该操作。例如:
//M_PI/4.0 is 45 degrees, you can make duration different from 0 if you want to show the rotation, if it is 0 it will rotate instantly
SKAction *rotation = [SKAction rotateByAngle: M_PI/4.0 duration:0];
//and just run the action
[yourNode runAction: rotation];
发布于 2013-12-31 01:28:34
只需在不使用操作的情况下执行此操作:
sprite.zRotation = M_PI / 4.0f;
在Swift 4中:
sprite.zRotation = .pi / 4
发布于 2014-03-31 18:11:08
使用预定义的值会更快:
sprite.zRotation = M_PI_4;
这些在math.h中预定义的常量以文字形式提供,可用于减少M_PI / 4.0等值的实际处理
https://stackoverflow.com/questions/19390064
复制相似问题