已解决(我认为,请参阅编辑)
在 displayObject 的父级调用 local3DToGlobal 后,hitTestPoint 只给了我错误。我让父母打电话给它,因为这就是我发现坐标正确的方式(不知道为什么,来自http://actionscript.org/forums/showthread.php3?t=190115的想法)有什么想法吗?
import flash.display.Shape;
import flash.geom.Point;
var circle:Shape = new Shape();
circle.graphics.beginFill(0x0000FF);
circle.graphics.drawCircle(40, 40, 40);
circle.z= 30;
addChild(circle);
stage.addEventListener(KeyboardEvent.KEY_UP, checkIt);
function checkIt(e:Event){
trace(circle.hitTestPoint(40,40,true));
var pos3D= new Vector3D(circle.x,circle.y,circle.z);
var globalLoc;
//This line doesn't break hitTestPoint, but it doesn't give the correct
//global x,y projected coordinates of the circle
globalLoc=circle.local3DToGlobal(pos3D);
trace (globalLoc);
//This line breaks the hitTest but is the only way I can get the correct
//global x,y projected coordinates of the circle.
globalLoc=circle.parent.local3DToGlobal(pos3D)
trace (globalLoc);
trace(circle.hitTestPoint(40,40,true));
}
stop();
编辑:想看一些奇怪的东西吗?我为圆圈添加了一个容器。现在检查两次(按任意键两次):你得到
真的
错误(就像上次一样)
真实(好的,更好)
真实(奇怪)
真的 (...)
真的 (...?)
import flash.display.Shape;
import flash.geom.Point;
import flash.display.MovieClip;
var circle:Shape = new Shape();
circle.graphics.beginFill(0x0000FF);
circle.graphics.drawCircle(40, 40, 40);
circle.z= 30;
var cont = new MovieClip();
addChild(cont);
cont.addChild(circle);
stage.addEventListener(KeyboardEvent.KEY_UP, checkIt);
function checkIt(e:Event){
trace(circle.hitTestPoint(40,40,true));
var pos3D= new Vector3D(circle.x,circle.y,circle.z);
var globalLoc;
//This line doesn't break hitTestPoint, but it doesn't give the correct
//global x,y projected coordinates of the circle
globalLoc=circle.local3DToGlobal(pos3D);
trace (globalLoc);
//This line breaks the hitTest but is the only way I can get the correct
//global x,y projected coordinates of the circle.
globalLoc=circle.parent.local3DToGlobal(pos3D)
trace (globalLoc);
trace(circle.hitTestPoint(40,40,true));
}
stop();
编辑:我认为的解决方案:
在函数外声明 pos3D 和 globalLoc
和
将圆圈放入容器中。
抱歉,我没有示例的固定代码,只是在完整项目中实现了它。
奇怪的东西,AS3。