cocos 2 d-xでスライドスクリーンが上から下、左から右と判断した場合
1352 ワード
今日.私は1つの小さいゲームを书いて、判断するため、スクリーンはあちらから滑ってきたので、1つの小さいロジックの判断があって、くだらない话は多く言いませんでした.直接コードをつけて、コードは解釈があります.
//論理はこうです.のタッチの開始時に、、、初めてクリックした座標を取得..そして終わる頃.最後のクリックポイントを取得します...自分で紙を作ったほうがいいです.の座標を描いて自分で計算する...~
bool StartScene::ccTouchBegan(CCTouch *touch, CCEvent *event)
{
// X Y
CCPoint touchPoint = touch->getLocation(); // OpenGL ( cocos2d-x , )
touch->getLocationInView();
firstX = touchPoint.x;
firstY = touchPoint.y;
return true;
}
void StartScene::ccTouchMoved(CCTouch *touch, CCEvent *event)
{
return;
}
void StartScene::ccTouchEnded(CCTouch *touch, CCEvent *event)
{
// X Y
CCPoint touchPoint = touch->getLocation(); // OpenGL ( cocos2d-x , )
endX = firstX - touchPoint.x;
endY = firstY - touchPoint.y;
touchx = touchPoint.x;
touchy = touchPoint.y;
CCLog("firstX %d firstY %d touchx %d touchy %d", firstX, firstY, touchx, touchy);
CCLog(" firstX - touchPoint.x %d firstY - touchPoint.y %d", endX, endY);
// X Y , X , , Y ,
if (abs(endX) > abs(endY))
{
//
//
if (endX > 0)
{
//
doLeft();
}
else
{
//
doRight();
}
}
else
{
//
//
if (endY > 0)
{
//
doDown();
}
else
{
//
doUp();
}
}
}
//論理はこうです.のタッチの開始時に、、、初めてクリックした座標を取得..そして終わる頃.最後のクリックポイントを取得します...自分で紙を作ったほうがいいです.の座標を描いて自分で計算する...~