Android游戏的onTouchEvent错误
问题描述:
任何人都可以帮助我解决这个错误getPointerCount()
,getX()
和getY()
?在这条线Android游戏的onTouchEvent错误
多个标记
方法
getPointerCount()
是未定义的类型MotionEvent
代码
int pointerIndex;
public boolean onTouchEvent(MotionEvent event)
{
float xPosition1 = 0;
float yPosition1 = 0;
float xPosition2 = 0;
float yPosition2 = 0;
for (pointerIndex = 0; pointerIndex < event.getPointerCount(); pointerIndex++) //Error
{
if (pointerIndex == 0)
{
xPosition1 = event.getX(pointerIndex);// Error
yPosition1 = event.getY(pointerIndex);//Error
}
if (pointerIndex == 1)
{
xPosition2 = event.getX(pointerIndex);//Error
yPosition2 = event.getX(pointerIndex);//Error
}
}
答
getPointerCount()
可以从API级别5.如果开始你使用比Android 2.0更早的任何SDK,你会成为ge那个错误。
你会想要包含logcat的输出:捕获异常并在编辑你的问题后粘贴到这里。 – Femi 2011-06-11 16:43:01