Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Mouse Sensitivity #164

Open
SeiferTim opened this issue Apr 25, 2013 · 2 comments
Open

Suggestion: Mouse Sensitivity #164

SeiferTim opened this issue Apr 25, 2013 · 2 comments

Comments

@SeiferTim
Copy link

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;
        }
@Dovyski
Copy link
Member

Dovyski commented May 4, 2013

👍 I like it!

@greysondn
Copy link

Three things here.

First, it seems like either failing to escape the game/application window despite running the flixel-based cursor past the edge of it is a potential issue. I've added actually testing this against some of our code to check that, but it's a familiar one to me when speed in an application != system-wide speed for the cursor's motion. (The question comes down to, are the system cursor and the flixel/flash cursor actually at the same location in screen space? If they are, no problem. If they aren't, well, this.)

Second, I'm wondering where PhotonStorm will leave us during the resolve of #163 ; as part of the tools there is the class FlxMouseControl which may help to both augment and better support this feature (depending, of course, on whether it's even worth merging in). Unfortunately the classes there are a little muddled; that class depends on his FlxExtendedSprite for part of the features (or is it the other way around?)

Third, I think it's a great idea (and I'm sure the code's great but again, on my list for now)! Off the top of my head, I can't think of a use that isn't first person, but the ability to adjust control sensitivity is seemingly essential, to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants