沿着绘制的路径拖动对象

发布于 2024-09-19 04:47:50 字数 91 浏览 2 评论 0原文

与问题相同: 我需要沿着由不同类型的图形(如直线、曲线等)组成的以编程方式绘制的路径拖动组件。

我已经用谷歌搜索过它,但没有成功。 有什么想法吗?谢谢!

Same as the question:
I need to drag a component along a programmatically drawn path composed by different kinds of graphic, like lines, curves, etc.

I've already googled it, but with no success.
Any ideas? thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

亣腦蒛氧 2024-09-26 04:47:50

以下是您绘制的线性弯曲路径。您可以对任何方向使用类似的方法。

  • 添加点击事件监听器。
    (开始拖动)

  • 沿着 x 跟踪用户的鼠标
    例如方向。

  • 继续绘制组件的 x 和y 作为
    鼠标 x 相对于
    绘制路径的 x。

  • 当用户离开时停止重新定位
    鼠标

如果可能的话从这里开始 &如果您有疑问,请返回代码。

The following is say for a linearly curved path drawn by you. You can use similar method for any direction.

  • Add an Event listener for click.
    (That starts drag)

  • Track the user's mouse along x
    direction for example.

  • Keep plotting the component's x & y as
    Mouse x changes with respect to the
    drawn path's x.

  • Stop relocating as user leaves the
    mouse

Start with this if possible & be back with code if you get doubts.

時窥 2024-09-26 04:47:50

如果您的绘图部分已完成,那么您可以使用二维 ByteArray。 ByteArray 的大小将是舞台的大小,这个二维数组将设置为零,意味着所有舞台位置都设置为零。当绘制任何曲线或直线时,将这些位置设置为 1。现在您至少知道您的对象可以移动到哪里,有效位置是那些设置为 1 的位置。
现在第二部分是如何使用鼠标或键盘在有效路径或位置上移动对象。

您将使用 Event.EnterFrame 来平滑、快速地移动对象,

1--使用键盘。
使用向上键将对象移动到上方位置,如果该位置或位置设置为其他位置,则对象将不会向上移动,其他情况也是如此。

2--使用鼠标移动事件,检测MouseY位置以相对MouseY当前位置向上或向下移动,如果位置设置为1,则分别移动它。

希望这会引导您走向正确的方向......

If your drawing part is complete then You can use two dimensional ByteArray. The size of the ByteArray will be the size of your stage, this two-dimensional array will be set to zero, means all your stage locations are set to zero. When any curve or line is drawn , set those locations to one. Now you know at-least where your object can move, the valid locations are those which are set to one.
Now the second the part is how to move an object on the valid path or location using mouse or keyboard.

You will be using Event.EnterFrame for smooth and fast movement of the object,

1--using keyboard.
use up key to move object to upper location if that position or location is set to one else the object will not move Up, same for others.

2-- using mouse move event, detect MouseY position for moving UP or DOWN w.r.t current position of MouseY , and move it respectively if location is set to one.

Hope, this will guide you in right direction...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文