0

我正在尝试将平移和缩放添加到我用 processing.js 编写的应用程序中,这是我的代码:

boolean surfaceTouchEvent(MotionEvent event) {
pointNum=event.getPointerCount();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
//User is pressing on finger
float x0=event.getX(0);
float y0=event.getY(0);
mode = false; //DRAG
break;
case MotionEvent.ACTION_POINTER_DOWN:
x1=event.getX(0);x2=event.getX(1);
y1=event.getY(0);y2=event.getY(1);
float z4 = dist(x1,y1,x2,y2);
mode = true; // pinch
break;
case MotionEvent.ACTION_POINTER_UP:
// User is released one of the fingers.

break;
case MotionEvent.ACTION_MOVE:
if (mode = false){
x1=event.getX(0)-x0;
y1=event.getY(0)-y0;
}
if (mode = true){
x1=event.getX(0);x2=event.getX(1);
y1=event.getY(0);y2=event.getY(1);
float z3 = dist(x1,y1,x2,y2);
if ( z3 > z4 ){ 
zoom += 0.1;
}
else if ( z3 < z4){
zoom -= 0.1;  
}
}
break;
}
return super.surfaceTouchEvent(event);
}

我保存了较旧的位置,以防 MotionEvent.ACTION_POINTER_DOWN 用于缩放,以防 MotionEvent.ACTION_DOWN 用于平移。例如,我需要这个旧位置来比较新距离和旧距离的缩放

这是错误:

compile:
    [javac] Compiling 2 source files to C:\DOCUME~1\T0P4568\LOCALS~1\Temp\android893850823480544580.pde\bin\classes
    [javac] C:\DOCUME~1\T0P4568\LOCALS~1\Temp\android893850823480544580.pde\src\changethispackage\beforesubmitting\tothemarket\sketch_may28a\sketch_may28a.java:118: variable x0 might not have been initialized
    [javac] x1=event.getX(0)-x0;
    [javac]                  ^
    [javac] C:\DOCUME~1\T0P4568\LOCALS~1\Temp\android893850823480544580.pde\src\changethispackage\beforesubmitting\tothemarket\sketch_may28a\sketch_may28a.java:119: variable y0 might not have been initialized
    [javac] y1=event.getY(0)-y0;
    [javac]                  ^
    [javac] C:\DOCUME~1\T0P4568\LOCALS~1\Temp\android893850823480544580.pde\src\changethispackage\beforesubmitting\tothemarket\sketch_may28a\sketch_may28a.java:125: variable z4 might not have been initialized
    [javac] if ( z3 > z4 ){
    [javac]           ^
    [javac] 3 errors

请帮忙!

4

1 回答 1

0

好的,您显然在使用 processing.org,它将其代码编译为 java。

解决方案很简单:预初始化x0y0z4设置为默认值,例如0

这只是为了安抚java编译器,它不够聪明,无法理解b在读取它们时,它们已经被初始化了。

于 2012-09-23T16:09:08.843 回答