基于中心点旋转和缩放多个精灵的位置? [英] Rotate and scale the POSITION of several sprites based on a center point?

查看:73
本文介绍了基于中心点旋转和缩放多个精灵的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些指导,因为我没有找到有关该主题的文档或主题.我的场景中有许多精灵节点,用户可以随意拖动它们.此外,我需要用户能够选择多个精灵和

I'm looking for some guidance as I haven't found documentation or threads regarding the topic. I have numerous spritenodes in my scene that a user can drag around at will. Additionally, I need the user to be able to select multiple sprites and

  • 基于中心点旋转所选精灵的位置根据选择了哪些精灵来计算(即.如果精灵被选中的已经在一个圆圈中,并且用户旋转编队,每个精灵的位置应该旋转和保持圆圈.

  • rotate the positions of the selected sprites based on a center point calculated based on which sprites were selected (ie. if the sprites that were selected are already in a circle formation, and the user rotates the formation, each sprite's position should rotate and mainain the circle.

再次基于中心缩放所选精灵的位置根据选择的精灵计算的点(即.如果选定的精灵呈圆形,用户缩放形成,圆圈应该相应地变大或变小

scale the positions of the selected sprites, again, based on a center point calculated based on which sprites were selected (ie. if the selected sprites are in a circle formation and the user scales the formation, the circle should get bigger or smaller accordingly

我将需要处理其他事件,但这应该让我开始.我已经在维护选择了哪些精灵并改变它们的位置(单个精灵和多个精灵).我不知道如何旋转和缩放他们的位置.

There will be other events I'll need to handle, but this should get me started. I am already maintaining which sprites are selected and changing their positions (single sprites and multiple sprites). I'm at a loss as to how to rotate and scale their positions.

有人能指出我正确的方向吗?

Can someone point me in the right direction?

推荐答案

这是一种不同的方法,但您可以做的是:

This is a different approach, but what you could do is :

  1. 创建容器SKNode
  2. 创建一个 SKNode ,将其命名为 spriteGroup 或类似名称,然后添加您想要以您描述的方式连接到该节点的任何精灵.
  3. 将 spriteGroup 添加到 containerNode.
  4. 将 spriteGroup 集中在容器节点的 0,0 位置.例如,如果 spriteGroup 的宽度为 100 且高度为 100 ,则您希望它的位置为 -50,-50.

现在您可以旋转/缩放/移动容器并实现所需的功能.

Now you can rotate/scale/move the container and achieve the desired functionality.

这是一个例子:

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;

这篇关于基于中心点旋转和缩放多个精灵的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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