MouseMoves: 1-to-1 Movement

1
  • 17 favourites

Stats

3,158 visits, 4,482 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.

The mouse is a very useful tool in gaming because of its precise movements. By tracking a sprite to the mouse cursor it can be used in variety of ways.

To track a sprite to the cursor there are only a few steps.

The first is to add a sprite and the mouse object to the objects panel.

*Note that the mouse object needs to be added in order use any of the attributes of the mouse in the events panel.

Also, make sure there is an instance of the sprite in the layout.

Then open the events panel to add our events.

This is what you want to see. What it means is that for every tick (another way of saying always) the Sprite object will be set to the position of the mouse in both the X and Y coordinates.

Go ahead and click on the Run Layout button to test it out. If all is well the sprite should be following the mouse wherever it goes.

To go one step further, the default cursor (the arrow) can be removed through this event:

What this does is on the start of layout, when things are playing, the mouse cursor will be set to none.

Various Ways to Use: Basic

Player control

The most obvious use is using it to control the player. This will be your main character.

Crosshairs

This can also be used as the aim of your gun to shoot objects when you click.

Custom Cursor

If the game requires a cursor, you can simply use this trick to replace the standard arrow cursor with your own unique one. It could be a star, or a hand, or maybe even a carrot!

Various Ways to Use: Advanced

Conditional Tracking

The tracking could be set so that objects only follow the cursor under specific conditions. For example, after the object is clicked or when it is rolled over.

If coupled with a toggle switch it could be used to create a different type of drag-and-drop.

The tracking could also be restricted within a specific area, or only when two sprites are overlapping.

  • 0 Comments

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