This is my first post. I'm an experienced Lua programmer but a Löve newbie.
1. Wish list item: getting and setting the shape of the mouse cursor.
2. Given a fair number of polygon-shaped objects, maybe overlapping, inside which of these is the mouse cursor? Any better way than just searching through all of them every time?
Where is the mouse?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Where is the mouse?
1. There is an SDL function that does that, but it's pretty shit. I'd recommend you simply hide the cursor and draw an image at the mouse coordinates instead.
2. To find if the mouse is inside a convex polygon, you could use a right-of-test. vrld gave an excellent explanation for that here. The physics module provides a method for checking if a point is inside a shape, so that's also an option.
If you have thousands of polygons, that might be too slow - in which case you'll have to sort some of them out, perhaps using a quadtree.
2. To find if the mouse is inside a convex polygon, you could use a right-of-test. vrld gave an excellent explanation for that here. The physics module provides a method for checking if a point is inside a shape, so that's also an option.
If you have thousands of polygons, that might be too slow - in which case you'll have to sort some of them out, perhaps using a quadtree.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Where is the mouse?
The shape of the cursor? You mean, you want to change its appearance? Then just hide the cursor with love.mouse.setVisible(false), then draw your own cursor with love.graphics.draw(newCursor, love.mouse.getX(), love.mouse.getY()).
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- josefnpat
- Inner party member
- Posts: 955
- Joined: Wed Oct 05, 2011 1:36 am
- Location: your basement
- Contact:
Re: Where is the mouse?
Thank you! Learn something new every day.Taehl wrote:The shape of the cursor? You mean, you want to change its appearance? Then just hide the cursor with love.mouse.setVisible(false), then draw your own cursor with love.graphics.draw(newCursor, love.mouse.getX(), love.mouse.getY()).
Missing Sentinel Software | Twitter
FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: Where is the mouse?
There are some love.run optimizations (fixes?) that need to be done in order to do this properly.Taehl wrote:The shape of the cursor? You mean, you want to change its appearance? Then just hide the cursor with love.mouse.setVisible(false), then draw your own cursor with love.graphics.draw(newCursor, love.mouse.getX(), love.mouse.getY()).
Just make it handle events before love.update instead of after love.draw. Then the cursorImage will feel more responsive. Otherwise, there is at least a whole millisecond of sleep before you get each event (mouse position, keyboard keys, etc.).
Code: Select all
function love.run() --LOVE 0.7.2
if love.load then love.load(arg) end
local dt = 0
-- Main loop time.
while true do
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
end
-- Process events.
if love.event then
for e,a,b,c in love.event.poll() do
if e == "q" then
if not love.quit or not love.quit() then
if love.audio then
love.audio.stop()
end
return
end
end
love.handlers[e](a,b,c)
end
end
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics then
love.graphics.clear()
if love.draw then love.draw() end
end
if love.timer then love.timer.sleep(1) end
if love.graphics then love.graphics.present() end
end
end
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Where is the mouse?
Come to think of it... Is there any reason it's not done that way in the default love.run?
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: Where is the mouse?
That is the default behaviour in 0.8.0.
Re: Where is the mouse?
So it is! And if you don't believe him, here's proof.thelinx wrote:That is the default behaviour in 0.8.0.
I'm gonna shove this in the wiki entry next to the 0.7.2 version. The 0.6.x parts should get removed since they're pretty irrelevant now and take up space. If anyone needs to know really old versions of love.run they can look in the code repository history.
Who is online
Users browsing this forum: RetroKevin and 13 guests