gpt4 book ai didi

ios - Sprite Kit - 绘制带有多色边框的圆

转载 作者:搜寻专家 更新时间:2023-11-01 07:27:33 24 4
gpt4 key购买 nike

我想画一个类似这样的圆:

image desc

我将让不同的对象与圆圈交互(碰撞),但对象将根据触摸的颜色进行不同的交互。

这可以使用贝塞尔曲线路径来完成吗?我希望将圆圈的每种颜色设置为不同的变量。

我最初的想法是在 photoshop 中绘制圆圈并将其导入 Sprite Kit,但我不知道如何通过这种方式将颜色分成不同的变量。

最佳答案

将对象作为 png(来自 photoshop 或其他软件)导入到您的游戏中,当节点与其发生碰撞时,检测它接触的点并计算 x 和 y 与圆心的差异。即使圆圈在旋转,只要您已经将颜色映射到“区域”,这也应该始终告诉您碰撞物体撞击的颜色。有道理吗?

或者,您可以创建一个透明圆 (SKShapeNode) 并将八个 SKShapeNode 弧作为该透明圆的子级。故意放置它们。这增加了一个好处,即每个对象都是一个单独的对象,可以有自己的 strokeColor 和自己的触摸方法。它们需要能够碰撞,而父透明圆圈需要忽略碰撞才能正常工作。

至于如何检测圆的哪个部分被击中,我会这样做:

给定一个被分成 8 个大小相等的饼 block 的圆,您应该能够根据碰撞点相对于圆心的 x 和 y 值来确定哪个部分发生了碰撞。例如,假设 Y 轴是两个部分之间的分界线,每个部分有四个部分(见图),您可以首先按象限缩小碰撞范围,如下所示:

Circle with 8 sections

cx, cy = 碰撞 x 和 y 值ox, oy = 圆心(原点)的 x 和 y 值

伪代码:

if cx > ox && cy > oy, then the collision occurred in quadrant 1
if cx > ox && cy < oy, then the collision occurred in quadrant 2
if cx < ox && cy < oy, then the collision occurred in quadrant 3
if cx < ox && cy > oy, then the collision occurred in quadrant 4

由于每个象限中有两个部分,因此您可以进一步细化此逻辑,通过比较差异来确定两个部分中的哪个部分发生了碰撞

伪代码:

if the difference between cx and ox > the difference between cy and oy, then the collision occurred in Section 2
else the collision occurred in section 1

将这些逻辑组合到一个嵌套的 if-else 语句中,您将得到如下内容:

伪代码:

if cx > ox && cy > oy, then the collision occurred in quadrant 1
......if the difference between cx and ox > the difference between cy and oy, then the collision occurred in Section 2
......else the collision occurred in section 1
if cx > ox && cy < oy, then the collision occurred in quadrant 2
......if the difference between cx and ox > the difference between cy and oy, then the collision occurred in Section 3
......else the collision occurred in section 4
if cx < ox && cy < oy, then the collision occurred in quadrant 3
......if the difference between cx and ox > the difference between cy and oy, then the collision occurred in Section 6
......else the collision occurred in section 5
if cx < ox && cy > oy, then the collision occurred in quadrant 4
......if the difference between cx and ox > the difference between cy and oy, then the collision occurred in Section 7
......else the collision occurred in section 8

喂!

关于ios - Sprite Kit - 绘制带有多色边框的圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34971802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com