Home Button News Button About & FAQ Button Members Button In.Dev Button Play Button Forum Button Resources Button Links Button Contact Button
Main Logo

Written by Chronic Chronic
Posted on 2/May/2007
Scrolling a View with your mouse

In this tutorial i'm going to explain a really simple way of scrolling around a view using your mouse. In the past I used to do a region checking method to check where my mouse cursor is and apply the correct movement to the view. While there isn't really anything wrong with this method if its what you need in your game, there is a much simpler way to achieve it.

First of all a little preparation is needed. Add a background to your project and then draw some random lines in it, save it and add it to a room and make sure its tiling in both horizontal and vertical directions. This is basically so we can prove the view is moving around when we come to test it, so feel free to skip this part if you wish.

Next we add a new object to the project, and place this any where in to a room.

Once you have done that, set your room to the width and height you want, for example purposes i'll use 1000x1000. Now enable view 0 and also make it visible when room starts. Leave the size of the view and port at the default sizes of 640x480. Set the object to follow to object0 (assuming you never renamed the object). I also suggest to set the room speed to 60, this helps to keep the slight delay between the mouse and object to a minimum.

Now comes the coding part, all 2 lines of it. Add the following to an End Step event.

  x = mouse_x;
  y = mouse_y;

Thats it, you're done. Run the game and move around your mouse, you should see the view moving around appropriately. However it may look a little fast, this can easily be solved by editing your view again and changing the horizontal speed (hsp) and the vertical speed (vsp) to whatever suits your needs.

Keep in mind that object0 is essentially a mouse cursor, so why not give it a sprite and hide the regular windows cursor in the global game settings.


Eo Logo   Link to Us | Feeds
2004 - 2018 © Eo
Website by House of Ninzha & Simon Donkers