Mouse Position

by Forum_account
Mouse Position
Provides a way to get pixel-precise mouse coordinates. [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Forum_account.MousePosition##version=3

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:


Version 3
Date added: Aug 25 2011
Last updated: Oct 16 2011
6 fans
With BYOND's traditional mouse procs you can get the exact pixel location of the mouse cursor, but only when a mouse event happens. For example, when the mouse crosses the boundary between two tiles, the MouseEntered event is triggered. However, when the player moves the mouse entirely within a tile, no mouse events are being called.

This library creates the client/MouseUpdate() proc which is called every time it detects mouse movement. All you have to do is this:

// enable mouse position tracking

// update the crosshair position when the mouse moves
MouseUpdate(tx, px, ty, py)
mob.crosshair.screen_loc = "[tx]:[px - 16],[ty]:[py - 16]"

Version 3
• Added support for a resolution value of 16.

Version 2
• Made MouseDrag() also trigger MouseUpdate

Version 1
• Initial posting


Bravo1: (Jun 1 2012, 3:22 pm)
I noticed that there's no support for different world.icon_size values.

Personally half my projects use 64 as the icon size, but I have a project that uses 16 as well. All it would need is an if() check and two icons, or perhaps just one file that uses the icon size as a variable for the icon state that's used. If you want. I'll make the file (I kind of HAVE to at this point) and I'll provide a public link for you to download it and you can just modify the code to support it?

It's up to you, I'm just letting you know 0__0

Forum_account: (Sep 28 2011, 4:21 am)
I haven't done any testing so I have no idea. My guess is that it would cause significant CPU usage with 100 players because having 100 players by itself is enough to cause decent CPU usage no matter what they're doing.

If performance is that important you can adjust the resolution used so that mouse events will be detected every 8, 4, 2, or 1 pixel that the mouse moves. You lose some precision but decrease the CPU usage.
Avainer1: (Sep 27 2011, 10:15 pm)
Does this use a lot of CPU? Lets say a game with about 70-100 players using it.
Gigimoi: (Sep 18 2011, 2:14 pm)
Good to know, I'll be using this now <3
Forum_account: (Sep 18 2011, 11:40 am)
Gigimoi wrote:
It stops tracking once you click&hold.

I just posted an update so it'll now track the mouse when you click and drag. I also changed the name of the icon file so it's less likely to clash with names of icon files in projects that use the library.