Greeting guru,
How can love engine detect a mouse clicked on my character sprite ?
From the doc provided, I only saw code to capture input from keyboard and mouse
How can I tell my program to increase my score when my mouse clicked on enemy image object?
Request sample code to detect image onclick event
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Request sample code to detect image onclick event
Well, then you're half way there. You now only have to compare the location of the mouse to the location you draw the Image (technically, they're not really sprites).
In pseudocode it'll be something like:
In pseudocode it'll be something like:
Code: Select all
function love.mousepressed(x, y)
if x >= draw_x and x <= draw_x + width and y >= draw_y and y <= draw_y + height then
score = score + 1
end
end
Help us help you: attach a .love.
Re: Request sample code to detect image onclick event
os, there is no
logic like
from your suggested code, imagine it's a polygon, then using ur code might end up trigger the increase score even click outside the image
logic like
Code: Select all
my_enemey.onClick {
score = score + 1
}
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Request sample code to detect image onclick event
Nope. That's not even valid Lua.
Well, most of the time a rectangular or circular bounding box is precise enough. if you really want pixel-perfect clicking, you'd need to use a Shape, set its position to the same location as the image and then run myshape:testPoint(x, y) on it. If it returns true, you clicked on the image. If you want to see it used in an actual unfinished game, you could take a look at http://github.com/gvx/Conq-rer.weilies wrote:from your suggested code, imagine it's a polygon, then using ur code might end up trigger the increase score even click outside the image
Help us help you: attach a .love.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot], pericles and 7 guests