【问题标题】:Rotate and scale the POSITION of several sprites based on a center point?基于中心点旋转和缩放几个精灵的位置?
【发布时间】:2013-11-13 21:37:37
【问题描述】:
我正在寻找一些指导,因为我没有找到有关该主题的文档或线程。我的场景中有许多精灵节点,用户可以随意拖动它们。
此外,我需要用户能够选择多个精灵和
我将需要处理其他事件,但这应该让我开始。我已经在维护选择了哪些精灵并更改了它们的位置(单个精灵和多个精灵)。我不知道如何旋转和缩放它们的位置。
有人能指出正确的方向吗?
【问题讨论】:
标签:
rotation
position
scale
sprite-kit
skspritenode
【解决方案1】:
这是一种不同的方法,但你可以做的是:
- 创建容器SKNode
- 创建一个 SKNode ,将其命名为 spriteGroup 或类似名称,然后添加您想要以您描述的方式连接到该节点的任何精灵。
- 将 spriteGroup 添加到 containerNode。
- 将 spriteGroup 居中于容器节点的 0,0 位置。例如,如果 spriteGroup 的宽度为 100 且高度为 100 ,则您希望它的位置为 -50,-50。
现在您可以旋转/缩放/移动容器并实现所需的功能。
这是一个例子:
SKNode *container = [[SKNode alloc]init];
SKNode *group = [[SKNode alloc]init];
for (int index = 0;index < 4;index++)
{
SKSpriteNode *sprite = [[SKSpriteNode alloc]initWithImageNamed:@"santa.png"];
sprite.anchorPoint = CGPointMake(0, 0);
sprite.position = CGPointMake(index * 100, 0);
[group addChild:sprite];
}
CGRect groupRect = [group calculateAccumulatedFrame];
group.position = CGPointMake(-groupRect.size.width/2, -groupRect.size.height/2);
[container addChild:group];
[self addChild:container];
container.position = CGPointMake(512, 384);
container.xScale = .5;
container.yScale = .5;
container.zRotation = 45 * M_PI /180;