- Home /
Question by
alexwong817 · Aug 06, 2016 at 07:51 PM ·
c#mousepositiondrawingshape
C# - How to find the mouse position?
I was trying to draw a shape onto the screen using SwinGame. However I don't know how to set the shapes x, y to be at the mouse's position. (31th Line) in GameMain. Any helps?
GameMain.cs
using System;
using SwinGameSDK;
using System.Text;
namespace MyGame
{
public class GameMain
{
public static void Main()
{
Shape myShape = new Shape ();
//Open the game window
SwinGame.OpenGraphicsWindow ("GameMain", 800, 600);
SwinGame.ShowSwinGameSplashScreen ();
//Run the game loop
while (false == SwinGame.WindowCloseRequested ())
{
//Fetch the next batch of UI interaction
SwinGame.ProcessEvents ();
//Clear the screen and draw the framerate
SwinGame.ClearScreen (Color.White);
//SwinGame.DrawFramerate(0,0);
//Draw onto the screen
if (Input.MouseClicked (MouseButton.LeftButton))
{
SwinGame.DrawText ("The mouse works", Color.Black, 12, 200);
SwinGame.MousePosition();
myShape.Draw ();
SwinGame.RefreshScreen (60);
}
}
}
}
}
Shape.cs
using System;
using SwinGameSDK;
namespace MyGame
{
public class Shape
{
Color _color = Color.Green;
float _x = 0;
float _y = 0;
int _width = 100;
int _height = 100;
//properies
public Color Color
{
get { return _color; }
}
public float X
{
get{ return _x; }
}
public float Y
{
get { return _y;}
}
public int Width
{
get { return _width;}
}
public int Height
{
get { return _height;}
}
public void Draw()
{
SwinGame.FillRectangle (_color, _x, _y, _height, _width);
}
public static bool IsAt(Point2D pt,float x,float y,float w, float h)
{
return true;
}
}
}
Comment