Where is the mouse?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
negester
Prole
Posts: 9
Joined: Fri Nov 18, 2011 4:41 am

Where is the mouse?

Post by negester »

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?
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Where is the mouse?

Post by nevon »

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.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Where is the mouse?

Post by Taehl »

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+.
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Where is the mouse?

Post by josefnpat »

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()).
Thank you! Learn something new every day.
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
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Where is the mouse?

Post by TechnoCat »

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()).
There are some love.run optimizations (fixes?) that need to be done in order to do this properly.
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
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Where is the mouse?

Post by Taehl »

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+.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Where is the mouse?

Post by thelinx »

That is the default behaviour in 0.8.0.
User avatar
hryx
Party member
Posts: 110
Joined: Mon Mar 29, 2010 2:28 am
Location: SF<CA<USA

Re: Where is the mouse?

Post by hryx »

thelinx wrote:That is the default behaviour in 0.8.0.
So it is! And if you don't believe him, here's proof.

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 134 guests