简体   繁体   English

如何获得 Phaser3 精灵顶部的坐标?

[英]How can I get a coordinate of the top side of a Phaser3 sprite?

I'd like to find out a top coordinate of a snippet.我想找出片段的顶部坐标。 The idea is to make a line between a point and the top of the green element.这个想法是在一个点和绿色元素的顶部之间画一条线。

How can I find or calculate this coordinate.我怎样才能找到或计算这个坐标。 I know the size of the box and angle.我知道盒子的大小和角度。

Here is a source code where I create a purple line.这是我创建一条紫色线的源代码

Here is a gif example.这是一个 gif 示例。

游戏截图

Thanks!谢谢!

As fas as I understand, rotation center cx, cy should be at the top of rope.据我所知,旋转中心cx, cy应该在绳子的顶部。

Top point of the net has coordinates网的顶点有坐标

tx = cx + ropelen * Cos(angle)
ty = cy + ropelen * Sin(angle)

If base point of sprite differs from top point, but lies below by dy , you can find its coordinates with the same formula using ropelen + dy如果精灵的基点与顶点不同,但低于dy ,则可以使用ropelen + dy使用相同的公式找到其坐标

If base point of sprite differs from top point, but lies left by dx , you can find its coordinates with the same formula using sqrt(ropelen^2 + dx^2 ) and angle angle + atan(dx/ropelen)如果精灵的基点与顶点不同,但位于dx左侧,则可以使用sqrt(ropelen^2 + dx^2 ) 和 angle angle + atan(dx/ropelen)使用相同的公式找到其坐标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM