添加平移和缩放错误

时间:2012-05-28 10:42:33

标签: compiler-errors processing

我正在尝试将pan和zoom添加到我在application.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

请帮忙!

1 个答案:

答案 0 :(得分:0)

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

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

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