我正在嘗試找出根據用戶在屏幕上觸摸來確定移動哪個方向的最佳方法。所以說我得到一個二維位置23x和320y我需要然後返回以下左,右,上,下。根據觸摸位置確定移動方向
目前我使用的代碼不是非常可靠,我想知道如果有人可以建議我一個更好的方式做到這一點。
感謝
if (at_position.x <= width*2/3 && at_position.x >= width*1/3 && at_position.y <= this->screenHeight*2/3)
{
return UP;
}
else if (at_position.x <= width*2/3 && at_position.x >= width*1/3 && at_position.y >= this->screenHeight*1/3)
{
return DOWN;
}
else if (at_position.x <= this->screenWidth*2/3 && at_position.y >= this->screenHeight*1/3 && at_position.y <= this->screenHeight*2/3)
{
return LEFT;
}
else if (at_position.x <= this->screenWidth*1/3 && at_position.y >= this->screenHeight*1/3 && at_position.y <= this->screenHeight*2/3)
{
return RIGHT;
}
謝謝,完美的作品 – 2012-07-20 08:14:37
感謝大家幫助 – 2012-07-20 08:14:50