Cursors, Point, Differences. C# in WinForms -
i have been working on 1 bit of code week , far have had no answer work around error coming across. error on line var diff = cursor.position - playerpoint;
, error occurs because cannot use (-) operand between windows.point
, drawing.point
coding convert seems convert expression involved in.
the commented out code different attempt @ same method produces same error. got 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 method isn't seen through above code there may resolve in 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); }
since cursor
windows forms / gdi+ class, , use of system.windows.point
indicates use wpf have problem. classes not inter-exchangeable.
if using wpf: instead of cursor.position
, can use mouse.getposition(application.current.mainwindow);
pointed out here.
if using wf: use system.drawing.point
way, not system.windows.point
.
still, subtracting points isn't possible. should write yourself, or better, construct new point , math in constructor call.
Comments
Post a Comment