gpt4 book ai didi

canvas - KineticJS Container.getIntersections 非常慢

转载 作者:行者123 更新时间:2023-12-04 05:21:40 26 4
gpt4 key购买 nike

我需要检测我的 HTML5 Canvas 中的碰撞(我使用的是 KineticJS 库),到目前为止,我已经使用我自己的方法来检测某个点是否在某个形状内。

我最近注意到 Container 类中的一个方法 getIntersections(point) 应该完全符合我的要求。然而,它似乎非常慢,所以当在 Canvas 上移动一个对象并为每个新位置使用该方法时,它变得无法使用。

有没有人使用这种方法进行碰撞检测?如果没有,是否有关于 HTML5 Canvas 中碰撞检测的任何提示?我无法检测一个点是否在旋转了一定度数的矩形内。

最佳答案

https://github.com/ericdrowell/KineticJS/issues/150

这正是您所需要的。

okay, to be clear, there are two ways to get an intersected shape based on mouse position:

1) getIntersection() - preferred 2) getIntersections() - very slow, and should be used for special situations

the getIntersection() method is blazingly fast, and returns an object containing information about the intersection point, such as a reference to a KineticJS shape if one is there, or pixel color information.

the getIntersections() method does the same thing, except that it iterates through and redraws every single node in the stage in order to return a collection of intersections that may have been layered on top of eachother.

99 times out of a 100, you're probably just interested in the visible intersected node which is at the top of nodes beneath it.

I've actually considered removing the getIntersections() method entirely, but haven't because there are some special situations when you actually do need a collection of intersections. At this time, I haven't been able to find a way to speed up getIntersections, although I'll keep looking into it.

关于canvas - KineticJS Container.getIntersections 非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13630869/

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