0
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {

    if (_nextProjectile != nil) return;

    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    [[SimpleAudioEngine sharedEngine] playEffect:@"pew-pew-lei.caf"];

    CGSize winSize = [[CCDirector sharedDirector] winSize]; 

    CGRect rect = CGRectMake(imgArrow.position.x, imgArrow.position.y,imgArrow.contentSize.width, imgArrow.contentSize.height); 

    if(CGRectContainsPoint(rect, location))
    {
        **_nextProjectile = [[CCSprite spriteWithFile:@"newarrow.png"]retain];
        _nextProjectile.position = ccp(430,190);**

        [imgArrow runAction:[CCSequence actions:
                             [CCRotateTo actionWithDuration:0 angle:0],
                             [CCCallFunc actionWithTarget:self selector:@selector(finishShoot)],
                             nil]]; 

        [blankBow setVisible:true];
        [imgArrow setVisible:false];   
        [walkAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"bow1.png", 0]]];

        [walkAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"bow2.png", 1]]];

        [walkAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"bow3.png", 2]]];

        walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.2f];

        self.walkAction = [CCRepeatForever actionWithAction:
                           [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];

        self.walkAction.tag = 1;
        [blankBow runAction:_walkAction];

        CCSprite *sprite = blankBow;

        CCCallBlock *block = [CCCallBlock actionWithBlock:^{
            [sprite stopActionByTag:1];
        }];
        CCDelayTime *time = [CCDelayTime actionWithDuration:0.3];
        [sprite runAction:[CCSequence actions:time, block, nil]];

        if(flagmultitouch == TRUE)
        {  
            id actionMove = [CCMoveTo actionWithDuration:1.5 
                                                position:ccp(-48,160)];
            id actionMoveDone = [CCCallFuncN actionWithTarget:self 
                                                     selector:@selector(spriteMoveFinished:)];
            [_nextProjectile runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];

            flagmultitouch = FALSE;  
        } 

        if(_nextProjectile !=nil)
            _nextProjectile.tag = 2;
    }
    else
    {

    }

    return YES;
}

問題は

_nextProjectile = [[CCSprite spriteWithFile:@"newarrow.png"]retain]; _nextProjectile.position = ccp(430,190);

init メソッドで __nextProjectile を初期化しているときに ccTouchBegan メソッドが機能しません.. _nextProjectile = [[CCSprite spriteWithFile:@"newarrow.png"]retain]; _nextProjectile.position = ccp(430,190); ccTouch では、Touch が実行されるたびに初期化するようになりました。何か助けて?!!

4

1 に答える 1

2

同じレイヤーのタッチを有効にします。

-(void)onEnter
{
    [super onEnter];

    self.touchEnabled = YES; //In Cocos2d 1.0: self.isTouchEnabled
}



- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView: [touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

}
于 2013-03-20T10:48:57.043 に答える