I have been working on this one bit of code all week and so far have had no answer that fully work around the error I am coming across. The error is on the line var diff = Cursor.Position - playerPoint;
, this error occurs because you cannot use the (-) operand between a Windows.Point
and a Drawing.Point
but the coding to convert it seems to only convert it for the expression it is involved in.
The commented out code is a different attempt at the same method but it produces the same error. Anyone got anything on this?
private void tmrMoving_Tick(object sender, object value, Type targetType,
object parameter, CultureInfo culture, EventArgs e)
{
System.Drawing.Point dp = (System.Drawing.Point)value;
var playerPoint = new System.Windows.Point(dp.X, dp.Y);
var cursPoint = new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y);
// var playerPoint = new System.Windows.Point(player.Location.X, player.Location.Y);
var diff = Cursor.Position - playerPoint;
var speed = Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y);
if (speed > 10)
{
diff.X /= speed / 10;
diff.Y /= speed / 10;
}
player.Location += new System.Drawing.Point((int)diff.X, (int)diff.Y);
}
Edit If a method isn't seen through the above code there may be a resolve in the below:
private void tmrMoving_Tick(object sender, object value, Type targetType,
object parameter, CultureInfo culture, EventArgs e)
{
var cursPoint = new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y);
var playerPoint = new System.Windows.Point(player.Location.X, player.Location.Y);
var diff = Cursor.Position - playerPoint;
var speed = Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y);
if (speed > 10)
{
diff.X /= speed / 10;
diff.Y /= speed / 10;
}
player.Location += new System.Drawing.Point((int)diff.X, (int)diff.Y);
}