开发者

Why aren't the member variables in the following object maintaining their state?

开发者 https://www.devze.com 2023-03-29 03:56 出处:网络
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

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消