Skip to content

Creating a GUI: Adding the mouse

Quajak edited this page Aug 24, 2020 · 8 revisions

The correct way to access the mouse position in Cosmos is through the MouseManager class.

Creating a mouse is quite difficult because Cosmos has removed the pre-built mouse device. We have to make our own mouse device, which is hard for newcomers. But, to facilitate our work, we'll download a pre-built mouse device. You'll then have to place it in your project, change the namespace, and use it. Let's do that now!

Drawing a mouse is now very simple. Add a reference to the Mouse device, then in our previous InitGUI() function, place this code:

Mouse m = new Mouse(800, 600); // Note that you'll have to specify the screen resolution (width and height).
bool OK = true; // Directly using true will cause debugging issues, and even if you disable it, (to make the GUI not lag) it's still very useful to just disable the GUI.
while (OK)
{
   m.Draw(driver); // Draws the mouse with the specified driver
   driver.Update(0, 0, Width, Height); // Updates the screen as a whole to reduce flicker.
}

Well done! You now have a 100% working and flawlessly moving mouse. ~ ShiningLea

Clone this wiki locally