Drag the layout (using Scroll To X)

1

Attached Files

The following files have been attached to this tutorial:

.capx

dragthelayout.capx

Download now 186.74 KB

Stats

4,498 visits, 7,795 views

Tools

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 13 Apr, 2014. Last updated 19 Feb, 2019

We will see how to drag to the X axis your Layout / Game Screen with your mouse.

Step 1 - Create Variables

DragOn Number = 0 It will determine if we are trying to drag the screen

ClickPosition Number = 0 Where we start to drag

TraveledPosition Number = 0 The distance traveled from the first click to the actual position

Step 2 - Events

Mouse On Left Button Clicked

--- System Set Value ClickPosition to Mouse.X

Mouse Left Button is Down

--- System Set Value DragOn to Mouse.X

Mouse Left Button is Down

System DragOn = 1

System Every TIck

--- System Set TraveledPosition to ClickPosition - Mouse.X

--- System Set Scroll X to scrollx+TraveledPosition

    Here we calculate where we need to go from the traveled distance. So in short, we can click wherever, we will just drag the screen, like on smartphone 


Mouse On Left Button released

--- System set DragOn to 0

    We stop the script !

And thats all!

You can change Mouse from Touch to make it works on Smartphone... That is that easy, yes !

And if you want to add Y movement, you just need to copy and paste Variable and change X into Y...

Thank you for reading, waiting for your comments !

Cheers !

.CAPX

dragthelayout.capx

Download now 186.74 KB
  • 0 Comments

Want to leave a comment? Login or Register an account!