如何在Cocos2d中实现CCSprite的操作?

时间:2013-01-23 14:57:22

标签: ios cocos2d-iphone ccsprite

我正在尝试实施此方法:

-(void) SpriteThouch
{
    CCSprite *actionEffect = avatar;
    id jump = [CCJumpBy actionWithDuration:1 position: ccp(0, 0) height:50 jumps:1];
    id sequence = [CCSequence actions: jump, nil];
    [actionEffect runAction:sequence];
}

成为一个带有字符的精灵,我正在使用包含所有字符的 .png ,并使用 .plist 来选择每一个字符。 我的问题是当我触摸它们时,我找不到让角色跳跃的方法。跳转方法有效,但是当我尝试将其实现为触摸操作时,它不会执行任何操作。 我正在尝试这种方法:

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

    UITouch *touch = [touches anyObject];

    if ([touch tapCount] == 1)
    {
        CCSprite *actionEffect = avatar;
        id jump = [CCJumpBy actionWithDuration:1 position: ccp(0, 0) height:50 jumps:1];
        id sequence = [CCSequence actions: jump, nil];
        [actionEffect runAction:sequence];
    }
}

UITapGestureRecognizer *gr = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector (SpriteThouch:)] autorelease];
[gr setNumberOfTapsRequired: 1];
[[[CCDirector sharedDirector] view] addGestureRecognizer:gr];
你可以帮帮我吗?谢谢!

0 个答案:

没有答案