Flex 3:碰撞检测和碰撞后移动物体

发布于 2024-11-06 06:10:19 字数 636 浏览 0 评论 0原文

我正在创建一个调度应用程序,该应用程序在 2 周的日历时间线上显示项目(包含在画布中)。如果用户决定将项目移动一天,我需要检查移动的项目是否会与任何其他现有项目重叠。如果是这样,两个项目之一将需要沿 y 轴向下移动屏幕,直到两个项目不再重叠。

我创建了一个循环遍历用于创建项目的中继器项目的函数...该函数的最终结果是一个包含以下内容的 arrayCollection:

0. the id number within the repeater
1. the project title
2. x coordinate
3. y coordinate
4. the width of the project
5. the height of the project

我还创建了一个函数,它接受数组集合中的两个对象和确定它们是否重叠。

但是,我无法找出一个工作循环,该循环遍历数组集合,比较其中的每个项目,检查它们是否重叠,如果重叠则移动项目,然后继续进行下一个项目。

另外,我需要确保移动一个项目不会使其与另一个项目重叠。

有什么想法吗?

编辑

弄清楚了... 每次移动任何项目时,我最终都必须将每个元素的 y 值重置为 0,然后重新评估它们是否发生碰撞。

I am creating a scheduling application that shows projects (wrapped within a canvas) on a 2 week calendar timeline. If the user decides to move a project over by a day, i need to check and see if the moving project would then overlap with any other existing projects. If it does, one of the two projects would need to move down the screen along the y axis until the two projects no longer overlap.

I've created a function that loops through a repeater item which is used to create the projects... the end result of this function is an arrayCollection that holds:

0. the id number within the repeater
1. the project title
2. x coordinate
3. y coordinate
4. the width of the project
5. the height of the project

I have also created a function that takes the two objects within the array collection and determines if they're overlapping.

I can not, however, figure out a working loop that goes through the array collection, compares each item within it, checks to see if they overlap, moves the project if they do overlap, and then continues onto the next project.

Also, I need to make sure that moving one project will not make it overlap with another.

Any ideas?

EDIT

Figured it out...
I ended up having to reset each elements y value to 0 each time any project is moved and then re-evaluating whether or not they collide.

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

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

发布评论

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

评论(1

空城之時有危險 2024-11-13 06:10:19

由于项目的性质,这个问题非常难以回答,因为每次交互以及您想要完成的任务都是不同的。

话虽如此,如果是我,我会尝试采用完全数据驱动的方法。有一个“项目日历”对象,它存储它需要的所有信息(主要是开始和结束时间戳,因为它们是通用的),然后将其放置在有意义的数据结构中,可以是数组,也可以是其顺序的双向链表时间线。

从这里开始,就需要限制数据上的下一个(或上一个)项目的开始时间和结束时间之间的移动。您需要一个自定义组件才能将时间戳转换为用户可以表示的内容。

我过去做过类似的事情,至少可以说这不是一件容易的事。祝你好运。

This is extremely hard to answer because of the nature of the project since every interaction and what you're trying to accomplish is different.

With that said, if it was me, I'd try to go a fully data driven approach. Have a 'project calendar' object that stores all the info it needs (mostly start and end timestamps since those are universal) and then place it in a data structure that would make sense, either an array or a doubly linked list of their order in the timeline.

From there it's a matter of limiting movement between the start and end time for the next (or previous) project on the data. You'll need a custom component to be able to translate the timestamp into something representable to the user.

I've done something similar in the past, it wasn't an easy task to say the least. Good luck.

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