Product Chat / A tip for people that use the mouse in their game, and then pause

Author
Message
Nevin
8
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 12th Dec 2020 23:16 Edited at: 13th Dec 2020 00:25
So. If you are using the mouse in your game. When pausing, the mouse will copy the cursor img, and deactivate the mouse when a player resumes the game. This happens in standalone

Not sure if anyone wants to know the fix for this. But all you have to do is..

Fix for deactivate mouse : in gamemenu.lua .. remove the DeactivateMouse() at the vary end.
I have not tested this, but you might need to activate mouse still when unpausing. I already put this in place so did not test without it.

fix for copy of the mouse img : in gamemenu.lua .. Add this to script: SetSpritePosition(your_mouse_cursor_sprite_name_that_you_use_in_other_scripts,200,200)

All though you could just remove the code that creates a new mouse sprite and just use SetSpritePosition on your old one... derp, im still playing around with it but hopfully this spreads some light on this.. you have to play around with the menu scripts to fit your game.

Sidenote: This means that when the player pauses the game, the variables from other scripts on the level are still active
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Dec 2020 00:33 Edited at: 13th Dec 2020 00:34
Simply replace ActivateMouse and Deactivate mouse with functions in your script that set an indication of whether the mouse is activated or not, then check that indication to decide whether you need to reactivate the mouse or not.

That way you don't need to mess with gameplayercontrol.lua.

Been there, done that, got all the T-Shirts!
PM
Nevin
8
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 13th Dec 2020 00:39 Edited at: 13th Dec 2020 00:41
thats awesome!

the gamemenu lua will still create a new mouse curser though when pausing. if you already have one active.

so editing that out and setting the one you already have active to the mouse x y is needed
Nevin
8
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 13th Dec 2020 00:43 Edited at: 13th Dec 2020 01:00
i also love that the variables are still there in the background. you could display player money or other info to the player. pretty cool
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Dec 2020 10:27
Are you saying you want to use your custom mouse sprite on the game menu when paused?

When resumed you should get your sprite back if you have coded it correctly.

Been there, done that, got all the T-Shirts!
PM
Nevin
8
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 13th Dec 2020 11:36 Edited at: 13th Dec 2020 11:40
I have it working for me.
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 15th Dec 2020 16:51 Edited at: 16th Dec 2020 02:09
This was an issue I had with my game as well. The solution I made was I replaced DeactiveMouse() with ActivateMouse() in the game pause script in titlebank. That way anytime I closed the menu, it would bring back my game cursor.

I think when I start focusing more my menu design parts of my game I'll use variable like you have there Amen
Store Assets - Store Link
Free Assets - Resource Link

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 15th Dec 2020 17:09 Edited at: 15th Dec 2020 17:09
The same trick can be used anywhere you use a global function, i.e. make a local copy of it.

For example if you wanted to use a different mouse pointer in the menus without having to mess about changing the default one or changing stock scripts you can do the following:


Obviously you would need to do similar for all the menus that you want to replace the mouse cursor on but as long as your script gets loaded after all the titlebank scripts it should work in theory.
Been there, done that, got all the T-Shirts!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 26th Dec 2020 12:31
Why don't use SetSpriteImage ( mySprite , myImage )
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 28th Dec 2020 21:59
Because the titlebank scripts will simply replace it next time you invoke the menu.
Been there, done that, got all the T-Shirts!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 29th Dec 2020 21:47
Quote: "Because the titlebank scripts will simply replace it next time you invoke the menu."

Hmm, it makes sense.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM

Login to post a reply

Server time is: 2024-04-25 17:59:18
Your offset time is: 2024-04-25 17:59:18