Scripts / [SOLVED] Using Mouse Cursor (sprite) to select a menu item

Author
Message
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 25th Apr 2020 19:52
I have given up for now trying to figure this out. I'm simply using a number selection. Of course, that can be only 1-9, and possibly '0' can be included.

There are two things that need to be done in preparation. Use the 'ActivateMouse()' command the create a sprite for the mouse cursor. That is as far as I have gotten. Now, I need to be able to use the mouse to move the sprite around the screen. I just am not able to figure that out using Lua. Actually, I have not really looked very closely at the Lua manual regarding this. Any ideas or help would be appreciated.
Alienware Aurora R7 with SSD 256GB boot drive ( C: ) and a secondary drive ( D: ) that is 2TB
Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz 3.19 with Intel Turbo-burst
Installed RAM 16.0 GB
64-bit operating system, x64-based processor
Windows 10 Home
NVIDIA GeForce GTX 1070 with 8192 MB GDDR5 and 8095 MB shared system memory

The author of this post has marked a post as an answer.

Go to answer
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 25th Apr 2020 20:08 Edited at: 25th Apr 2020 20:08
This post has been marked by the post author as the answer.
at top of script:

local mouse_spr = mouse_spr or CreateSprite( LoadImage( "scriptbank\\images\\mouse_cursor.png" ))

SetSpriteSize( mouse_spr, 1.5, -1 ) -- change value to resize mouse
SetSpriteOffset( mouse_spr, 0.75, 1.2 ) -- change to suit 'trigger' point of mouse pointer
SetSpritePosition( mouse_spr, 200, 200 ) -- initialise to off screen

in _main function:

local mx, my = g_MouseX, g_MouseY

SetSpritePosition( mouse_spr, mx, my )

then you can use the mx, my values to figure out where the mouse is on your menu or whatever
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-22 03:24:43
Your offset time is: 2024-12-22 03:24:43