我有问题。我想计算我的skishashap画布的屏幕上触摸的起点和终点之间的差,因此我创建了以下代码:
private void OnTouchEffectAction(object sender, TouchActionEventArgs args)
{
TouchTrackingPoint pt = args.Location;
SKPoint point =
new SKPoint((float)(canvas.CanvasSize.Width * pt.X / canvas.Width),
(float)(canvas.CanvasSize.Height * pt.Y / canvas.Height));
double StartX;
double StartY;
double EndX;
double EndY;
double Threshold = 100;
switch (args.Type)
{
case TouchActionType.Pressed:
StartX = point.X;
StartY = point.Y;
break;
case TouchActionType.Released:
EndX = point.X;
EndY = point.Y;
break;
}
}
但是无论我在哪里触摸屏幕,StartX和StartY始终为0。EndX和EndY是正确的坐标。
我在做什么错?
[Jason说:“ StartX和StartY在事件处理程序中本地声明,因此每次事件触发时它们都将初始化为0。如果希望它们在事件之间保持其值,则需要在类级别声明它们。 “