I'm trying to implement some simple 'draggable map' code so that instead of just clicking for where they want to move, they can hold down the click button and drag around the map. The issue is that once I start using this event listener in game it overrides the player's move click method.
Here is the code I have in game for this feature:
Code: Select all
public var mPos_x;
public var mPos_y;
const MIN:Number = 5;
const MAX:Number = 10;
public function initializeOpenSpace():void
{
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
}
//Takes initial position and begins calling 'Tick' method on every frame
function mouseDown(e:Event):void
{
mPos_x = mouseX;
mPos_y = mouseY;
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
addEventListener(Event.ENTER_FRAME,tick);
}
// Ends the 'Tick' method calling every frame
function mouseUp(e:Event):void
{
removeEventListener(Event.ENTER_FRAME,tick);
stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUp);
}
// Set move values to slightly more normal ranges
function clamp(val:Number, min:Number = MIN, max:Number = MAX)
{
return Math.max(min, Math.min(max, val))
}
// Performed on every frame the mouse is held down
function tick(e:Event):void
{
var move_x = mouseX - mPos_x;
var move_y = mouseY - mPos_y;
move_x = clamp(move_x, 5, 20);
move_y = clamp(move_y, 5, 20);
openSpace.panView( move_x , move_y, false, true);
mPos_x = mouseX;
mPos_y = mouseY;
}
The feature itself works well (although without linear interpolation), however it over rides the move function?
Where is the original '.addEventListener(MouseEvent.MOUSE_DOWN,OpenSpaceDoesAMethod);' code, and can I access it?
Many Thanks,
Nigel Clark