如何使用 Starling on Flash Develop (AS3) 将四边形转换为矩形?

How can i convert a Quad to a Rectangle using Starling on Flash Develop (AS3)?

我希望使用 "intersects"(来自 Starling)创建碰撞,但我不知道如何将我的四边形 "player" 和四边形 "block" 转换为矩形. 有人可以帮忙吗?

Quad 包含一个 getBounds public 方法,该方法 returns 一个新的矩形(如果在第二个参数中传入,则为更新的矩形),因此:

var playerRect:Rectangle = quadPlayer.getBounds(this);
var blockRect:Rectangle = blockPlayer.getBounds(this);
if (playerRect.intersects(blockRect)) {
   trace("Collision!");
}

现在,我正在使用 this 因为我不知道你的显示列表层次结构,也不知道你的四边形在哪个坐标系中,所以相应地调整。

http://doc.starling-framework.org/current/starling/display/DisplayObject.html

Transforming coordinates

Within the display tree, each object has its own local coordinate system. If you rotate a container, you rotate that coordinate system - and thus all the children of the container.

Sometimes you need to know where a certain point lies relative to another coordinate system. That's the purpose of the method getTransformationMatrix. It will create a matrix that represents the transformation of a point in one coordinate system to another.

http://doc.starling-framework.org/current/starling/display/Quad.html

getBounds(targetSpace:DisplayObject, out:Rectangle = null):Rectangle [override] Returns a rectangle that completely encloses the object as it appears in another coordinate system.