How to take an object with the mouse and drop it

M

molikayess

Guest
Hi , i'm not a coder , and i don't know how to take an object with the mouse , move it and drop it after . If u don't understand , i want to create a chessboard and idk how to move the piece with the mouse only . I tried with the up/down/left/right , but i cant move only one piece , because they all move . The mouse seems like the best option .
Thanks you if u can help me .
Sorry for my english language .
 

StormGamez

Member
Heya, ive got some code here for you to move you pieces, just make sure to set them back to a grid afterwards!

Code:
///Creation code for chess piece
//Keep you code here
move = false
can_move = false
placing = false

///Mouse enter event
can_move = true

//Mouse leave event
can_move = false

//Step event
if(mouse_button_pressed(mb_left) and placing = false)
    placing = true
} else placing = false

if(can_move = true and placing = true) {
     x =mouse_x
     y = mouse_y
}
Just make sure to put the things in the right events and your set!

PS. Make sure in the step event use the drag and drop align to grid and set it to the size of the checkered blocks on the board
 

StormGamez

Member
Hey by the way, a piece of advice, you should learn how to code as it will help with a lot when making games, the extreme basics only takes a few days to lean and after about 2 months you should be able to make basic games fairly easily if you try learn. (This is learning for about 2h per day)
The easiest play to learn off it Youtube so look for tutorials there
 
By the sounds of it, you are using object.x and object.y (or something similarly object based) to move the pieces. This will move every piece, regardless of whether you use a mouse or a keyboard. You should look into the differences between objects and instances and how and when you should manipulate either one.
 
M

molikayess

Guest
Hi , i wrote this code , and i put it in Step action :

Code:
///Déplacement
right = keyboard_check_pressed(vk_right);
left = keyboard_check_pressed(vk_left);
up = keyboard_check_pressed(vk_up);
down = keyboard_check_pressed(vk_down);



vitesse = 25;



while(keyboard_check_pressed(vk_enter)){



if right{
object11.x += vitesse;
}

if left{
object11.x -= vitesse;
}

if up{
object11.y -= vitesse;
}

if down{
object11.y += vitesse;
}
}
And i tried with IF instead of While , and it doesnt work too .

So i tried to put this new code in the "Press Space" action , and it doesnt work too .
Code:
///Deplacements

right = keyboard_check_pressed(vk_right);
left = keyboard_check_pressed(vk_left);
up = keyboard_check_pressed(vk_up);
down = keyboard_check_pressed(vk_down);



vitesse = 25

if right{
object11.x += vitesse;
}

if left{
object11.x -= vitesse;
}

if up{
object11.y -= vitesse;
}

if down{
object11.y += vitesse;
}
 
V

Vyking

Guest
*Says not a coder*
*but is on gm forums*

Dude, if you type a single line of code, that makes you a coder, doen't matter what your skill.
 
Last edited by a moderator:
M

molikayess

Guest
*Says not a coder*
*but is on gm forums*

Dude, if you type a single line of code, that makes you a coder, doen't matter what your skill.
So i'm a coder , not good but i'm ^^ , but can u solve my problem ?
 
Top