forked from AdamAtomic/flixel
-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Milestone
Description
I've made this change in my own code, and it's been pretty useful.
This just sets the scale a which the mouse cursor moves. In my current project, I have the game at 2x zoom, and I have my sensitivity at 1.25 so the mouse cursor is just a little faster than the 'regular' mouse.
I don't know if anyone else will find it useful or not...
Here's the changes I've made:
add to FlxG.as:
static public function set MouseSensitivity(Value:Number):void
{
mouse.sensitivity = Value;
}
Add to system/input/Mouse.as
protected var _sensitivity:Number;
public function get sensitivity():Number
{
return _sensitivity;
}
public function set sensitivity(Value:Number):void
{
_sensitivity = Value;
}
Add _sensitivity = 1;
to the Mouse.as constructor.
In Mouse.as, change the updateCursor function to this:
protected function updateCursor():void
{
//actually position the flixel mouse cursor graphic
_cursorContainer.x = _globalScreenPosition.x*_sensitivity;
_cursorContainer.y = _globalScreenPosition.y*_sensitivity;
//update the x, y, screenX, and screenY variables based on the default camera.
//This is basically a combination of getWorldPosition() and getScreenPosition()
var camera:FlxCamera = FlxG.camera;
screenX = (_globalScreenPosition.x - camera.x)/camera.zoom * _sensitivity;
screenY = (_globalScreenPosition.y - camera.y)/camera.zoom* _sensitivity;
x = screenX + (camera.scroll.x * _sensitivity);
y = screenY + (camera.scroll.y * _sensitivity);
}
In Mouse.as change getWorldPosition to this:
public function getWorldPosition(Camera:FlxCamera=null,Point:FlxPoint=null):FlxPoint
{
if(Camera == null)
Camera = FlxG.camera;
if(Point == null)
Point = new FlxPoint();
getScreenPosition(Camera, _point);
_point.x *= _sensitivity;
_point.y *= _sensitivity;
Point.x = _point.x + Camera.scroll.x;
Point.y = _point.y + Camera.scroll.y;
return Point;
}
Finally, in Mouse.as, change getScreenPosition to this:
public function getScreenPosition(Camera:FlxCamera=null,Point:FlxPoint=null):FlxPoint
{
if(Camera == null)
Camera = FlxG.camera;
if(Point == null)
Point = new FlxPoint();
_point.x *= _sensitivity;
_point.y *= _sensitivity;
Point.x = (_globalScreenPosition.x - Camera.x)/Camera.zoom;
Point.y = (_globalScreenPosition.y - Camera.y)/Camera.zoom;
return Point;
}