是否可以围绕 SpriteKit 中的任意点旋转节点? [英] Is it possible to rotate a Node around an arbitrary point in SpriteKit?

查看:23
本文介绍了是否可以围绕 SpriteKit 中的任意点旋转节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 SpriteKit 中的节点围绕一个任意点旋转?我现在可以操作节点的 anchorPoint,但如果我想使用的旋转点位于节点之外,这还不够.

Is there a way to rotate a Node in SpriteKit around an arbitrary point? I now I can manipulate the anchorPoint of my Node, but that is not sufficient if the rotation point I want to use lies outside of the Node.

在 SpriteKit 中实现这种旋转的最佳方式是什么?

推荐答案

既然您要求最佳方式,这里有一个效果很好(最好是主观的):

Since you're asking for the best way, here's one that works well (best is subjective):

创建一个 SKNode 并将其位置设置为旋转中心.将应该围绕该中心旋转的节点作为子节点添加到中心节点.将子节点的位置设置为所需的偏移量(即半径,例如 x + 100).更改中心节点的旋转属性以使子节点围绕中心点旋转.顺便说一句,cocos2d 也是如此.

Create an SKNode and set its position to the center of rotation. Add the node that should rotate around that center as child to the center node. Set the child node's position to the desired offset (ie radius, say x + 100). Change the rotation property of the center node to make the child node(s) rotate around the center point. The same works for cocos2d btw.

这篇关于是否可以围绕 SpriteKit 中的任意点旋转节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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