首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在精灵工具包中旋转精灵节点?

如何在精灵工具包中旋转精灵节点?
EN

Stack Overflow用户
提问于 2013-10-16 04:06:50
回答 5查看 39.6K关注 0票数 23

我正在做一个游戏,我在旋转一个精灵节点时遇到了麻烦,这是我拥有的代码;我必须添加什么才能将它旋转,比如说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];
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 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];  
票数 20
EN

Stack Overflow用户

发布于 2013-12-31 01:28:34

只需在不使用操作的情况下执行此操作:

sprite.zRotation = M_PI / 4.0f;

在Swift 4中:

sprite.zRotation = .pi / 4
票数 71
EN

Stack Overflow用户

发布于 2014-03-31 18:11:08

使用预定义的值会更快:

sprite.zRotation = M_PI_4;

这些在math.h中预定义的常量以文字形式提供,可用于减少M_PI / 4.0等值的实际处理

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19390064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档