0
ビットマップ画像をいくつかのポイントから私が触れた場所に移動しようとしています...しかし、うまく行かないものです。SurfaceViewでビットマップをタッチ位置に移動する方法は?
Render.javaは、ここで私はフラグが描画するときに、それをチェックするために触れ作成
public void run() {
Canvas canvas;
while (runFlag) {
long now = System.currentTimeMillis();
long elapsedTime = now - prevTime;
if (elapsedTime > 30){
prevTime = now;
if (touched ==true) {
matrix.postTranslate(touched_x, touched_y);
touched =false;
}
}
canvas = null;
try {
canvas = surfaceHolder.lockCanvas(null);
synchronized (surfaceHolder) {
if (touched ==true) {
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(picture, matrix, null);
touched = false;
}
}
}
finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
...それは良いアイデアではないようです(Threadクラスを拡張します)。
View.java(SurfaceViewクラス)
public boolean onTouchEvent(MotionEvent event) {
touched_x = event.getX();
touched_y = event.getY();
int action = event.getAction();
switch(action){
case MotionEvent.ACTION_DOWN:
touched = true;
break;
case MotionEvent.ACTION_MOVE:
touched = true;
break;
case MotionEvent.ACTION_UP:
touched = false;
break;
case MotionEvent.ACTION_CANCEL:
touched = false;
break;
case MotionEvent.ACTION_OUTSIDE:
touched = false;
break;
default:
}
return false;
}