开发者

multi touch..need help with cctouchesended

I've almost finished with my multi touch code for my game but I'm stuck with one more problem. This is done开发者_如何转开发 in Cocos2d btw :)

The player has a dpad on the left side and a button on the right, it works fine if i hold down on of the dpads and hold the jump button, so that he runs to the right and jumps.

The problem is once I lift my finger off the jump button all actions stop, so I have to lift and press my finger down again on the dpad...

this is my code for cctouchesended

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

////when the user has stopped touching the screen set the variables 
     ////back to false to stop its movement////

//self.myTouch = nil;
for (UITouch *touch in touches)
{
    if (moveRight == TRUE) {
    [player stopAction:RunForward];

    }
    if (moveLeft == TRUE) {
    [player stopAction:RunBackwards];

    }
    moveLeft = FALSE;
    moveRight = FALSE;
 //  jump = FALSE;
}



}


You would be better off mapping the logic to 2 buttons instead. Or at least for the jumping. The problem with the current code is that you are not checking to see which finger you lift. You could ad a check so if the touch that ended is on the left side of the screen then stop moving.

Also you don't need to compare a BOOL value to TRUE. Just do, "if (moveRight)". It is much better


You will want to keep reference to the HASH (touch.hash) and save that CCTouchesBegan

then in the function you have now (the release) you check which hash has been released.

so:

  1. in your ccTouchesBegan function you check which button is pressed:

    if (CCRectContainsPoint(sprite1.boundingbox,touchlocation)) { rightSideButtonHash = touch.hash; )

in the release you check the touch.hash against the rightSideButtonHash, and you know if it was that touch!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜