Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Get Mouse Position? #1

Closed
SpicyMelonYT opened this issue Sep 28, 2022 · 2 comments
Closed

How to Get Mouse Position? #1

SpicyMelonYT opened this issue Sep 28, 2022 · 2 comments
Labels
question Further information is requested

Comments

@SpicyMelonYT
Copy link

SpicyMelonYT commented Sep 28, 2022

Hi,

I would like to be able to get the mouse position of the window (Preferably the canvas area and not the title bar at the top too). I am using this repo to make a pixel sandbox game. This repo is so awesome and simple and it works great with my work flow. But I just can't seem to find any way to get the mouse position. I see a few things online but they all need to work within the top level statement and I don't know how to do that.

Would you be willing to add this functionality? And Perhaps even keyboard key input and mouse button input?

I managed to add my own implementation but It only gets the mouse position on the monitor and not on the window:
image

Thank you!

@Jallenbah
Copy link
Owner

Hi, glad you like it!

The PixelWindow repo is built on top of SFML.Net which is a .Net binding of SFML

In the Learn section of the official site you can see tutorials on how to do all sorts of things in SFML including input. Note that the tutorials use C++ as that is the language that the library is natively written in and available in, but the C# ends up being easy to figure out from their samples.

For an example of mouse input within a specific window, you can see an example of me using it in my Conway's Game of Life implementation in the HandleDrawingCells method within the GameOfLifeAppManager.cs file.

The PixelWindow system will give you a reference to the SFML RenderWindow in the OnLoad function. Store a copy of that in your app manager class when OnLoad runs, then you can use that to get the mouse pos relative to the window using

Mouse.GetPosition(_renderWindow);

There's also examples of key input in that game of life repo.

Hope this answers your question. I have no plans to add any kind of wrapper around the input to expose it within the PixelWindow class as there's a bunch of useful stuff that SFML exposes that you can use out of the box. As such the PixelWindow stuff will focus purely on pixel rendering, and for anything else you want to do, SFML can probably do it.

@Jallenbah Jallenbah closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2022
@SpicyMelonYT
Copy link
Author

Ah I see, that is totally ok and I will do what you said thank you! Plan b with asking that question was to get pointed in the right direction so thanks!

@Jallenbah Jallenbah added the question Further information is requested label Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants