Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 16th, 2012  |  syntax: C#  |  size: 0.79 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  public virtual void Update()
  2.         {
  3.             mouseState = Mouse.GetState();
  4.             if (mouseState.LeftButton == ButtonState.Pressed)
  5.             {
  6.                 if (dragging)
  7.                     position = new Vector2(mouseState.X, mouseState.Y); // il pezzo si muove seguendo il mouse
  8.  
  9.                 else if (IsMouseIn)
  10.                     dragging = true;
  11.             }
  12.  
  13.             else if (dragging)
  14.             {
  15.                 dragging = false;
  16.  
  17.                 int squareCenter = (int)board.SquareSize / 2;
  18.  
  19.                 Point casella = new Point((int)(position.X / board.SquareSize), (int)(position.Y / board.SquareSize));
  20.                 position = new Vector2(casella.X * board.SquareSize + squareCenter, casella.Y * board.SquareSize + squareCenter);
  21.             }