0

I am developing a mobile game using coco2d-x framework with C++ language. The platforms I target are IOS and Android.

I want to run some code when an user is pressing a sprite as long as he doesn't release the press without moving the finger. I went through the documentations and looked at the different callbacks (onTouchBegan, onTouchMoved, onTouchEnded) but couldn't find a way to solve my problem.

In fact i have sprites drawn on the screen to simulate directional controller. I want to move a character as long as the user is pressing on a directional sprite.

Is there a way to run some code as long as a sprite is pressed ?

4

1 回答 1

0

我会尝试这样的事情

onTouchBegan(...){
    //let player move
    //e.g. set some flag moving=true;
}
onTouchMoved(...){
   //query x and y distance of finger movement
   //cancel player movement if finger moved above a certain treshold
   //or alternatively check if the finger is now 
   //outside of the bounding box of your sprite
   //if so then
      //moving=false;
}
onTouchEnded(...){
    //stop movement if not already stopped before
    //moving=false;
}

在您的更新功能中,只要移动为真,您就可以简单地检查移动并执行您的代码。这是你的意思吗?

于 2015-04-13T06:58:46.867 回答