Using the mouse to move the camera (Click and drag)



  • So I'm trying to get the camera to sort of "follow" the mouse when you hold the middle button down, like in normal software. But I've been running into issues, and can't figure out how to do this well. How would I go about doing this?

    Something like this (Tiled Editor):
    Example

    i dunno check out my tumblr if you want (nsfw tho so watch yourself)
    http://carpetwurm.tumblr.com/
    (not nsfw version)
    https://carpetwurmlite.tumblr.com/

    0


  • No worry anymore! He's already got it working.


  • administrators



  • I helped him with this message:

    mousePositionChange = newMousePosition.substract(initialMousePosition); // or substract the other way around
    camera.scroll = initialCameraScroll.add(mousePositionChange); //or substract
    // I'm bad at vector math
    

    Note:

    • newMousePosition, initialMousePosition, initialCameraScroll are FlxPoints

    • initialMousePosition and initialCameraScroll is set when the mouse is pressed

    • It's pseudo-code. For the second line to work, you're gonna need to use FlxPoint.copyFrom():

    camera.scroll.copyFrom(initialCameraScroll.add(mousePositionChange)); //or substract
    

    And this is what he'd got:
    alt text

    Here's the class he used for the above gif: Pastebin


Log in to reply