Game Development Reference
In-Depth Information
public function get hitPointList():Vector.
< HitTestCoordinate > {
return _hitPointList;
}
public function get speed():int { return _speed; }
}
This class represents the square on the Stage. It has a given
speed at which it will move per second (50 pixels), and a vector
list of its collision test points. When it is added to the Stage, it
enumerates these points in the list. Other than this basic function-
ality, this class does nothing. Now, we
'
ll look at the class behind
the collision points.
public class HitTestCoordinate extends Sprite {
private var _point:Point;
public function HitTestCoordinate() {
visible = false;
_point = new Point(x, y);
}
public function get point():Point {
updatePoint();
return _point;
}
public function get pointGlobal():Point {
return parent.localToGlobal(point);
}
private function updatePoint():void {
_point.x = x;
_point.y = y;
}
}
This class is designed to be a visual tool for placing collision
points, so that they don
'
t have to be placed manually in code. Any
shape could be used to represent them; I chose a circle because it
is small and unobtrusive; the shape is, ultimately, irrelevant
because the Sprite hides itself on creation. It stores a point within
itself representing its position. In addition to providing access to
this point, it provides an accessorial method to return the point
already converted to the global coordinate space, which is how
we
'
ll need to measure the point for the hit test.
Search Nedrilad ::




Custom Search