The following two AS files contain statically available public methods. In Mouse.as, the trace statements correctly print the contents of both calls to getLocation(), which returns a Point in space (X,Y).
However, when passing the value from Mouse.as into HitTest.as, target.getLocation() always prints (0,0). Wha开发者_如何学编程t happens to the instance of GameObject when its passed into the second class that causes it to lose its value?
In GameObject
public function getLocation():Point2
{
return m_location;
}
In Block (extends GameObject)
if (Mouse.isPressing(this))
{
reset();
}
In Mouse
public static function isPressing(target:GameObject):Boolean
{
trace("T1: " + target.getLocation());
trace("M1: " + location);
return isDown() && HitTest.containsPoint(target, Mouse.getLocation());
}
In HitTest
public static function containsPoint(target:GameObject, location:Point2):Boolean
{
trace("T2: " + target.getLocation());
trace("M2: " + location);
return target.getLocation().GridX == location.GridX && target.getLocation().GridY == location.GridY;
}
精彩评论