多点触摸的一些代码

注: 该段代码只是我处理多点触摸时的一小部分,其中还有错误,后面已经修改掉了。

把这些放在这里,只是为了做一个纪念。 

public boolean onTouchEvent(MotionEvent event) {
ispointer = true;

int action = event.getAction() & MotionEvent.ACTION_MASK;
if(action == MotionEvent.ACTION_DOWN)
{
int px = (int) event.getX(0);
int py = (int) event.getY(0);
GCanvas.pointerPressedX = px;
GCanvas.pointerPressedY = py;
}
else if(action == MotionEvent.ACTION_UP)
{
GCanvas.resetPointer();
}


//不是游戏阶段的话,用Engine的相关方法处理。
if(GCanvas.state != C.STATE_GAME)
{
Engine.mouseEvents.add(event);
return true;
}

//小游戏
if(Engine.game == null || Engine.game.isClassicGame() == false)
{
return false;
}


//游戏阶段处理。。 特殊处理:

switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
this.pointerPressed(event, 0);
break;
case MotionEvent.ACTION_UP:
this.pointerReleased(event);
break;
case MotionEvent.ACTION_MOVE:
this.pointerDragged((int) event.getX(), (int) event.getY());
break;
case MotionEvent.ACTION_POINTER_DOWN:
this.pointerPressed(event, 1);
break;
case MotionEvent.ACTION_POINTER_UP:
this.pointerReleased(event);
break;
}
return true; 
}




private void pointerPressed(MotionEvent event, int index) { int px = (int) event.getX(index); int py = (int) event.getY(index); int bid = getBtnId(px, py); if (bid != -1) { pressId |= (1 << bid); } pressingId = pressId; } private void pointerReleased(MotionEvent event) { int index = event.getActionIndex(); int px = (int) event.getX(index); int py = (int) event.getY(index); int bid = getBtnId(px, py); if(bid != -1) { releaseId |= (1 << bid); pressingId &= ~(1 << bid); } //如果点到的不是按钮区 --- if(releaseId == 0) { pressingId = 0; GCanvas.keyKeptPressed = 0; } } protected void pointerDragged(int px, int py) { if (state != C.STATE_GAME || Engine.isUseGesture == false) { return; } int bid = getBtnId(px, py); if ((1 << bid) != pressingId) { pressingId = 0; GCanvas.keyKeptPressed = 0; } }

  

posted on 2012-10-24 14:23 千山万水_ 阅读(...) 评论(...) 编辑 收藏

导航

公告