Scrolling with mouse

0 favourites
  • 7 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hello! I tried looking through the FAQ, but didn't find something that quite helped me. Maybe I overlooked it, but here is what I'm trying to do:

    Rather than have the camera, follow a specific sprite or arrowkey, I'd like to scroll the 'map' by moving the mouse to the edges of the screen. As is seen in some strategy games.

    Is there some fancy way of achieving this that I have missed?

  • Two quick ideas :

    a) Invisible sprites at the edges of screen (parallax 0) and conditions to scroll the screen when mouse is overlapping them.

    b) Check each tick for absolute mouse position to detect if it's near edge of the screen.

    After you've detected where you wish to scroll, there are nice examples of how to scroll the screen in the FAQ thread. :)

  • I had not thought of the invisible sprite idea, I think I'll try that out for now, thanks!

    If people have other interesting ideas for the problem, do keep sharing.

  • Here's a working script:

    Remove the key conditions if you don't also want scrolling with wasd-keys.

    ScrollRate is how fast the screen scrolls in pixels each tick.

    MouseScrollArea is how large the trigger areas are at the sides.

    The advantage of this solution is that it's easy to copy-and-paste between projects and supports diagonal scrolling.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh, thank you very much! Looks like this will work better than what I had put in place.

  • Only just saw this post but yep I used an invisible sprite with ScrollTo behaviour that teleports to Mouse.X,Mouse.Y Every Tick..

  • I'm still looking for the perfect solution for my game, I've gone through several. (assigning and sending armies on an isometric map with pop up windows)

    Having the screen center on the cursor was prettiest, (scrollto the mouse each tick) but was annoying when opening and closing windows because the screen would snap to the cursor location. (letting the screen scroll under the windows made you feel dizzy, so it locked with them open.)

    Touching the edges felt logical, but felt jarring because it didn't ease in and out like I wanted. Plus, if you played in a window it would stop scrolling if your cursor ventured over the edge.

    I also used the invisible sprite with scrollto behavior, and had it chase the mouse rather than teleport. It still moved too much when trying to work.

    Right now I have it scrolling a speed set by the distance from the edge, but it's annoying because you accidentally scroll the screen when trying to click something near the edge, and it makes you miss.

    I will probably end up with almost touching the edge adds to a variable, and the value of the variable determines the speed of the scroll. Still have the problem of the cursor venturing too far and stopping though.

    Edit: Just stepped back and looked at it fresh because of this thread, and I think I have a different direction. I'm using the Touch drag demo for another game, and it works fine for the mouse as well. You click an non-clickable spot on the map and pull it to move it.

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