开发者

Touch is Currently Moving - Cocos2d

Is there a way to tell if the touch is currently moving? If so c开发者_高级运维ould someone lead me to the right place?


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

    UITouch *touch = [touches anyObject];
    location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    //Here urSprite is your CCSprite which you want to move
    CGRect urSpriteRect = CGRectMake([urSprite position].x - [urSprite contentSize].width/2, 
                          [urSprite position].y - [urSprite contentSize].height/2, 
                          [urSprite contentSize].height, [urSprite contentSize].width);

    if (CGRectContainsPoint(urSpriteRect, location)) 
    {
           checkFlag = TRUE;
           NSLog(@"You Touched the sprite!");
    }

}

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

    if(checkFlag){

          urSprite.position = location;
          NSLog(@"You are moving your sprite!");
    }
}

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

    checkFlag = FALSE;
    NSLog(@"Sprite stopped!");

}


If your layer has touches enabled, you can implement the following method in your layer to handle move events for touches...

-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜