From 27c93e4155d3665ad412cc69c99b0748cc54920c Mon Sep 17 00:00:00 2001 From: Toby Davis Date: Wed, 20 Nov 2024 09:09:40 -0500 Subject: [PATCH] Add frontCollidePoint to World.as Add the frontCollidePoint function that allows the punk.ui project to work. Code provided by the punk.ui wiki here: https://github.com/RichardMarks/punk.ui/wiki/Additional-function-on-World --- net/flashpunk/World.as | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/net/flashpunk/World.as b/net/flashpunk/World.as index aa9163b..766c9e1 100644 --- a/net/flashpunk/World.as +++ b/net/flashpunk/World.as @@ -995,6 +995,31 @@ } } + /** + * Returns the Entity at front which collides with the point. + * @param x X position + * @param y Y position + * @return The Entity at front which collides with the point, or null if not found. + */ + public function frontCollidePoint(x:Number, y:Number):Entity + { + var e:Entity, + i:int = 0, + l:int = _layerList.length; + do + { + e = _renderFirst[_layerList[i]]; + while (e) + { + if(e.collidePoint(e.x, e.y, x, y)) return e; + e = e._renderNext + } + if(i > l) break; + } + while(++i); + return null; + } + /** @private Adds Entity to the update list. */ private function addUpdate(e:Entity):void {