Dragging the Screen with Mouse and Touch

9

Index

Stats

13,420 visits, 33,744 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 7 Dec, 2012. Last updated 19 Feb, 2019

Hi All,

I have been working on a project that required the user to drag the screen using the mouse or touch and it was rather difficult but I have since (with help from forum members) been able to do this and I thought I would create a tutorial for others. This is really for if you have a level bigger than the screen size.

Dragging the Screen - Mouse

First thing, make sure you have selected Mouse as an input object.

You then need 5 Global Variables for this to work. They are all numbers and can start with an initial value of 0, I have called them: Dragging, DragScrollX, DragScrollY, DragMouseX, DragMouseY.

Now, there are two parts to getting this to work and the first one involves setting the global values when the mouse is either being pressed or not.

Create an event for the mouse:

Choose On Click and select Left and Clicked.

Then, Add two actions:

Choose System then select Set Value for Global Values. Choose DragMouseX from the drop-down list and write the value as Mouse.AbsoluteX.

Repeat this a second time but this time set DragMouseY to the value Mouse.AbsoluteY.

You should have:

Next create a second event for the mouse:

Choose Mouse Button is Down and select Left but this time, right click the event and Invert it.

You also need two actions for this event:

Set The Global Variables DragScrollX and DragScrollY to the values scrollX and scrollY so you now have:

Basically, when the mouse is not being pressed, it stores the currently X and Y value of the position of the screen and once the mouse is pressed is stores the position on the mouse pointer on the screen at that exact moment.

This second part can be the confusing part but bare with me, I promise you it will work!!

  • 4 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Is there a modification to the expression that can take layoutScale into account? If the scale is anything other than 1 this system breaks. I've been trying to figure this out to no avail. Your tutorial is great BTW! Cheers!

  • Thank you very much!

  • Thanks heaps! worked a treat