TX missing Mouse management (NOW IMPLEMENTED)
by Giuseppe De Francesco · in Torque X 2D · 07/02/2010 (8:26 am) · 1 replies
Hey guys,
coding the input for my new title (wich will be Windows as well) I've just noticesd that the Mouse management is part missing and part simply wrong (maybe just placeholders?). So... implementing a proper mouse management. This will be committed in the SVN repo as soon it's ready (very soon!).
~Pino
P.S.: Marking this as 3.1.5 Bug as well.
coding the input for my new title (wich will be Windows as well) I've just noticesd that the Mouse management is part missing and part simply wrong (maybe just placeholders?). So... implementing a proper mouse management. This will be committed in the SVN repo as soon it's ready (very soon!).
~Pino
P.S.: Marking this as 3.1.5 Bug as well.
About the author
In the software eng. field since 1981, in charge of R&D during last 10 years. IEEE Senior Member (and volunteer).
Associate Giuseppe De Francesco
DFT Games Ltd
As promised the Windows mouse management has been fixed in the Core engine: you’ll find it in the Commit Revision 42 (www2.xp-dev.com/sc/change/77988/42) of the SVN repository.
I decided to keep it outside the InputMap system because I really couldn’t figure any Use Case justifying that decision, thus I’ve added a static class Mouse inside the InputManager ignoring the bits of existent not working code. This class is updated by the core engine itself. The whole thing is within a #if !XBOX block.
HOW-TO use it:
First off you need to remember that the Torque coordinate system is quite different from the basic XNA, so your very first step shall be to set the camera you’re using in your player’s movement manager or in your Game Manager as it suits you (in the sample I’m also preparing a sight cursor ):
#if !XBOX InputManager.Mouse.SceneCamera = _camera; InputManager.Mouse.ShowTheMouse = false; _cursor = TorqueObjectDatabase.Instance.CloneObject<T2DSceneObject>("TSight"); TorqueObjectDatabase.Instance.Register(_cursor); #endif- Setting the SceneCamera property allows you to get the proper world coordinates for your cursor. Do not forget to set it back to null when you unload your level ;) If you don’t set the Scene Camera the class assumes that your scene size is just equal to the screen size.
- Setting ShowMouse to False makes the default cursor disappear so you can use your own object as mouse pointer.
Now you have all set to use it, just putting some code where you want to do something with it. Here an example from my shooter (in the ProcessTick of my MovementComponent):#if !XBOX _cursor.Position = InputManager.Mouse.CurrentPosition; _cannon.TrackMountRotation = false; _cannon.Rotation = T2DVectorUtil.AngleFromTarget(_cannon.Position, InputManager.Mouse.CurrentPosition); if (InputManager.Mouse.IsLeftButtonPressed) { if (!_fire.EffectPlaying) _fire.PlayEffect(false); // shooting using particles’ collisions } else { if (_fire.EffectPlaying) _fire.StopEffect(true); } #else // XBOX GamePad management Here #endifHere’s the list of the Mouse properties (with comments):
I hope you’ll enjoy it ;)
Pino