Mouse Position

by Forum_account
Mouse Position
Provides a way to get pixel-precise mouse coordinates.
ID:117785
 
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
mob
Login()
..()
track_mouse()

// update the crosshair position when the mouse moves
client
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
Another brilliant library. Thanks =D
Great Job
It stops tracking once you click&hold.
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.
Good to know, I'll be using this now <3
Does this use a lot of CPU? Lets say a game with about 70-100 players using it.
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.
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