Absolute Mouse

0 favourites
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I'm having difficulty understanding the difference between Absolute and regular Mouse.X - I'm using my own mouse pointer by putting a sprite in place of where the mouse is.

    I don't know what it is about my project but I can't reproduce what is happening here. I just don't understand how this is happening. If I set it to follow mouse.x it works fine, but if I set it to follow absoluteX its exponentially ahead of it.

    it doesn't matter if my mouse pointer layer is parallax 0,0 or 100,100

    can anyone help explain it? or has seen this?

    (I need to use Absolute because I change screen positions and I want the pointer to stay in place as the window snaps to a different part of the layout)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Mouse.AbsoluteX gives the number of screen pixels from the left of the canvas.

    Mouse.X does more. It basically maps where the cursor is to the games coordinates.

    Probably something like

    Mouse.x = (mouse.absoluteX/windowWidth+0.5)*originalWindowWidth*scale+scrollx

    I guess I’m not seeing how absolutex is more useful. Guess I need to try that use case you mention.

  • well the reason I need Absolute is a little bit complicated.

    basically I hide the mouse when not in use. The way I do that is I compare if the mouse has ever moved or was click to activate it.

    so when I jump to a different part of the layout the movement "wakes up" the mouse since the mouse is in a different position, if they are using the controller it messes things up like MouseOver etc... but mainly I don't want the mouse to wake up.

  • R0J0hound

    here is the mouse "waking up" when I switch screens because technically the x/y is moving when I jump to the new ScrollTo position in the layout.

    I'm trying to avoid it "waking up"

    here you see the mouse pointer go invisible after a few seconds of being idle. I hit the E key to go to the next screen and the movement makes the mouse visible again

  • I'd rather not shut off all mouse/keys control when they switch to gamepad. I'm trying to make it as seamless as possible: pickup a controller, it works and all the glyphs change, start using the mouse, they change back.

  • Oh I see now.

    You could still use mouse.x instead.

    I mean mouse.x-scrollx which would be relative to the scroll position. Aka even if the screen scrolled that relative position wouldn’t change.

    So it should just be a matter of replacing mouse.absolutex and y


    Mouse.x-scrollx and mouse.y-scrolly

  • R0J0hound oh that is a great idea. I guess I was thinking mouse.x was where it was in the layout. thanks will try that out!

  • I'm so confused...

    should the mouse pointer sprite be on a layer with 0 parallax?

  • I never use parallax but not using it with a cursor would make sense.

  • okay. I got it to reproduce the issue, you have to fullscreen it to see how it exponentially strays from the actual mouse pointer.

    mouselayer is 100,100 parallax


  • I mean, absolutex/y doesn’t take into account scaling or parallax at all. That’s why the position will differ from the actual mouse.

    Setting the sprite’s position to mouse.x/y will put it right at the mouse, but i don’t know what layer it uses by default. If you need the mouse position on a certain layer you can use mouse(layer).x/y.

    Or if you’re set on using absolutex/y you can adjust it to match with some trial and error:

    X = mouse.absolutex*scale+offset

    Just by eyeballing it it looks like you could start with a scale of 2 and an offset of 0. But any scale or resolution changes could through that off I’d imagine.

  • I think I figured it out, but I don't know how to fix it.

    my screen reso is 854x480 and when I Letterbox Fullscreen mode it stretches the screen to 1920x1080 upscaling the game.

    so my mouselayer has to be parallax 0,0 but then it thinks the bottom RIGHT corner of the screen is x/y:854,480 but because Letterbox is scaling it, it is really at x/y:1920,1080

    (oh maybe parallax doesn't matter?)

  • is there a variable that tells you the current stretch of the screen? can you access Letterbox Scale somehow? I searched the doc and couldn't find anything.

  • Best I can tell construct only provides the viewport* expressions to find the width of the view in layout coordinates.

    The browser object, in the c2 docs at least, mention screenWidth and screenHeight as values too.

    With js you can also get the width/height of the html canvas if you really want to handle it from scratch.

    There’s also the system expressions layertocanvasx/y and canvastolayerx/y expressions that may be useful.

    Does it only happen in full screen?

    Honestly for positioning things don’t use absolutex/y. You can use it to see if the mouse moved.

    Otherwise as an exercise in math you can map the absolute mouse position to the layout position in a correct way.


    Intuitively you should be able to put your cursor sprite on any layer and position the sprite with

    Set position to mouse(self.layer).x, mouse(self.layer).y

    And it’ll just work, full screen or not. If it doesn’t then it’s a bug I say.

    You can still utilize absolutex/y to check if there was mouse motion. Like

    Global number oldx = 0
    Global number oldy = 0
    Compare oldx <> mouse.absolutex
    Compare oldy <> mouse.absolutey
    — do something because the mouse moved
    Every tick
    — set oldx to mouse.absolutex
    — set oldy to mouse.absolutey
  • I'm just going to suggest something out the left field...

    Firstly, I had the same issue and need (consistent mouse pointer position) - what I found out was that the actual canvas size was different from the size specified in Construct - strangely only horizontally, and by a very weird amount - I got that "correct" value using the PlatformInfo Object - PlatformInfo.CanvasCssWidth/Height - piping that into my pointer formula gave me consistent behavior.

    Sidetracking aside, why not use the Pointer Lock feature coupled with On Movement and Mouse.MovementX/Y to drive the cursor sprite? Along with saving last position when doing any layout switching, that should give you full control.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)