Custom Mouse Cursors (Tutorial)

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
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Custom Mouse Cursors (Tutorial)

Post by BlackBulletIV »

As I recently had to customise the mouse cursor for my new prototype, I thought I'd write a tutorial on the subject. Here it is:

Custom Cursors in Love2D
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Custom Mouse Cursors (Tutorial)

Post by Lafolie »

I would add a sentence explaining that it's better to draw the image using a '0, 0' (top-left) origin if you want a traditional mouse pointer and not a crosshair. :)
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Custom Mouse Cursors (Tutorial)

Post by coffee »

I'm disappointed! You even't implemented normal/clicking states in your tutorial? That's bellow your usual quality! ;D
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Custom Mouse Cursors (Tutorial)

Post by BlackBulletIV »

Lafolie wrote:I would add a sentence explaining that it's better to draw the image using a '0, 0' (top-left) origin if you want a traditional mouse pointer and not a crosshair. :)
Good point.
coffee wrote:I'm disappointed! You even't implemented normal/clicking states in your tutorial? That's bellow your usual quality! ;D
Huh? I've no idea what you mean. If you've talking about keeping track of clicking and the like, that's going beyond the intended scope of this tutorial.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Custom Mouse Cursors (Tutorial)

Post by coffee »

BlackBulletIV wrote:Huh? I've no idea what you mean. If you've talking about keeping track of clicking and the like, that's going beyond the intended scope of this tutorial.
Since your tutorial was about teach how to use custom mouse cursors, I would think that fits in your intended scope of tutorial also cover custom "mouse states". As you guess something (quickly imagined) like this:

Code: Select all

function love.load()
  cursor_off = love.graphics.newImage("crosshair_off.png")
  cursor_on = love.graphics.newImage("crosshair_on.png") 
  cursor = cursor_off
  love.mouse.setVisible(false)
  love.mouse.setGrab(true)
end

function love.mousepressed(x, y, button)
   if button == 'l' then cursor = cursor_on end
end

function love.mousereleased(x, y, button)
   if button == 'l' then cursor = cursor_off end
end
-- or other better way of swap cursor of course
function love.draw()
  love.graphics.draw(cursor, love.mouse.getX() - cursor:getWidth() / 2, love.mouse.getY() - cursor:getHeight() / 2)
end
Ah but never mind! It's your tutorial and was only a silly provocation/suggestion. :P
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Custom Mouse Cursors (Tutorial)

Post by josefnpat »

It's also worth taking note that it may lag on some systems, and you want to offer an option to disable vsync!
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
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Custom Mouse Cursors (Tutorial)

Post by BlackBulletIV »

@coffee: Ah I see. I might just add that.
@josefnpat: Another good point. Though with all things I should add, I'll have to structure the tutorial a bit different I think.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Custom Mouse Cursors (Tutorial)

Post by BlackBulletIV »

For some strange reason, the wiki page I created for this tutorial isn't appearing in the tutorials category. And yeah, I've purged the tutorials page multiple times. Anyone know what's going on?
Post Reply

Who is online

Users browsing this forum: No registered users and 75 guests