Re: [Help] How to move object to mouse clicked loaction
Posted: Fri Sep 07, 2012 2:02 pm
I modified your game. Now its possible to select, deselect and move the image using the mouse.
I hope you wanted that.
For selecting, I needed a function to check if the mouse and the image collide.
You can get an explanation here: https://love2d.org/wiki/BoundingBox.lua
(In this case, a collision check for circles would be better, but leave that for later)
The code is fully commented, and yes, I know I have a bad english, so please don't complain.
Please ask if you have questions.
PS: Please don't forget, this code is only an example of how things work. You have to read the comments and try to understand the code, the syntax, the structure, the logic, etc, so you will be able to do it yourself later. I've partly made an error with writing all of the code for you. Please use it like it was made for.
I hope you wanted that.
For selecting, I needed a function to check if the mouse and the image collide.
You can get an explanation here: https://love2d.org/wiki/BoundingBox.lua
(In this case, a collision check for circles would be better, but leave that for later)
The code is fully commented, and yes, I know I have a bad english, so please don't complain.
Please ask if you have questions.
PS: Please don't forget, this code is only an example of how things work. You have to read the comments and try to understand the code, the syntax, the structure, the logic, etc, so you will be able to do it yourself later. I've partly made an error with writing all of the code for you. Please use it like it was made for.