【发布时间】:2010-10-13 10:11:19
【问题描述】:
我正在开发我的第一个 Android 平台视频游戏,作为一个晚上和周末的项目。
效果很好,但我对控制敏感度很不满意。
在这个游戏中,您在屏幕上左右移动一个对象。屏幕底部是一个“触摸板”,是您的手指应该放置的地方。
/-------------------------\
| |
| |
| |
| Game Area |
| |
| |
| |
| |
| |
/-------------------------\
| |
| Touch Area |
| |
\-------------------------/
我目前正在使用一个状态变量来保存“MOVING_LEFT, MOVING_RIGHT, NOT_MOVING”,并根据该变量在每一帧更新播放器对象的位置。
但是,我读取触摸屏输入并设置此状态变量的代码要么过于敏感,要么过于滞后,具体取决于我如何调整它:
public void doTouch (MotionEvent e) {
int action = e.getAction();
if (action == MotionEvent.ACTION_DOWN) {
this.mTouchX = (int)e.getX();
this.mTouchY = (int)e.getY();
}
else if (action == MotionEvent.ACTION_MOVE) {
if ((int)e.getX() >= this.mTouchX) {
this.mTouchX = (int)e.getX();
this.mTouchY = (int)e.getY();
if (this.TouchRect.contains(this.mTouchX, this.mTouchY)) {
this.mTouchDirection = MOVING_RIGHT;
}
}
else if ((int)e.getX() <= this.mTouchX) {
this.mTouchX = (int)e.getX();
this.mTouchY = (int)e.getY();
if (this.TouchRect.contains(this.mTouchX, this.mTouchY)) {
this.mTouchDirection = MOVING_LEFT;
}
}
else {
this.mTouchDirection = NOT_MOVING;
}
}
else if (action == MotionEvent.ACTION_UP) {
this.mTouchDirection = NOT_MOVING;
}
}
这个想法是,当有任何移动时,我会检查用户手指的先前位置,然后找出移动播放器的方向。
这不太好用,我想这里有一些 iPhone/Android 开发人员已经弄清楚如何通过触摸屏进行良好的控制,并可以提供一些建议。
【问题讨论】:
-
你能定义“效果不好”和“太迟钝或太敏感”吗?对其行为方式的描述将很有用
-
两个敏感意味着我将手指移动了十分之一英寸并且播放器在屏幕上..太滞后意味着我必须在整个屏幕上移动手指才能移动播放器一英寸. :)
标签: iphone android user-interface touchscreen