Game Development Reference
In-Depth Information
when deploying the game to comment out the last three lines of
the constructor, so these methods are not called.
public function get position():Point
{
return mPosition.clone();
}
public function dispose():void
{
removeEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin );
removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove );
removeEventListener(TouchEvent.TOUCH_END, onTouchEnd );
removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown );
removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove );
removeEventListener(MouseEvent.MOUSE_UP, onMouseUp );
}
There is an accessor for getting the current finger position,
which simply returns a copy of the internally stored position. We
return a copy, so this value can
t be accidentally modified and
mess up the internal mechanics of the controller. The dispose func-
tion should be self-explanatory by now. It does cleanup of listeners
to free up memory.
'
private function onTouchBegin( _evt:TouchEvent ):void
{
var newPosition:Point = new Point( _evt.stageX, _evt.stageY
)
newPosition = mCoordinateSpace.globalToLocal(newPosition);
if (Point.distance( mPosition, newPosition ) < = mDistance
Threshold )
{
mTouching = true;
onTouchMove( _evt );
}
}
private function onTouchMove( _evt:TouchEvent ):void
{
if (mTouching)
{
mPosition.x = _evt.stageX;
mPosition.y = _evt.stageY;
mPosition = mCoordinateSpace.globalToLocal(mPosition);
}
}
Search Nedrilad ::




Custom Search