Hey guys, I have been making a game, and I want it to place an object where-ever the mouse is when it clicks, but how would I do that? Right now all that I have done is create a cursor sprite as crosshairs and set that. Could you please help me with an example or a link? Thanks :D - Sledger721.
Mouse Questions
Started by tommyroyall, Jun 09 2012 09:34 PM
3 replies to this topic
#1
Posted 09 June 2012 - 09:34 PM
#2
Posted 09 June 2012 - 09:47 PM
To do something when the left mouse button has been pressed, you can use
(Otherwise, just search the GM manual for "mouse")
Use the two variables mouse_x and mouse_y when setting the position of the instance to be created. This will create it at the mouse's position.
if (mouse_check_button_pressed(mb_left))If you need codes for any other mouse buttons, I guess you can figure them out easily.
Use the two variables mouse_x and mouse_y when setting the position of the instance to be created. This will create it at the mouse's position.
#3
Posted 09 June 2012 - 11:05 PM
Ok now, but what if I have an object, and I want it to shoot in what-ever direction I click in? So that it has a full 360 degree spectrum of firing, and it fires towards wherever the mouse had clicked? And Thx TsukaYuriko :D.
#4
Posted 09 June 2012 - 11:19 PM
I assume you're going to make the object move by using GM's built-in speed and direction variables.
If you have an object which shoots things, e.g. a cannon, you can make its shots travel to the mouse's position using this:
If you have an object which shoots things, e.g. a cannon, you can make its shots travel to the mouse's position using this:
var ID; ID = instance_create(x, y, obj_shot); //or however your shot instances are created. Make sure you add the "ID =" part, though! ID.direction = point_direction(x, y, mouse_x, mouse_y); //using a dot after ID will refer to ID's variables (the variables of the shot) instead of my the cannon's. ID.speed = whatever speed you want the shot to travel at;
Edited by TsukaYuriko, 09 June 2012 - 11:20 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











