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
The most obvious use is using it to control the player. This will be your main character.
This can also be used as the aim of your gun to shoot objects when you click.
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
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.