質問

したいので無効化に触れるCCRect/スプライトの後で触れた?

私のinitメソッドのスプライト:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"testAtlas_default.plist"];
            sceneSpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"testAtlas_default.png"];

[self addChild:sceneSpriteBatchNode z:0];

dinosaur1_c = [CCSprite spriteWithSpriteFrameName:@"dinosaur1-c.png"];
[sceneSpriteBatchNode addChild:dinosaur1_c];

[dinosaur1_c setPosition:CGPointMake(245.0, winSize.height - 174.0)];

それをCGRectの位置とサイズのスプライトとしてそのパラメータ:

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchLocation = [touch locationInView:[touch view]];
    touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
    touchLocation = [self convertToNodeSpace:touchLocation];

    dinosaur1 = CGRectMake(dinosaur1_c.position.x - (dinosaur1_c.contentSize.width / 2), dinosaur1_c.position.y - (dinosaur1_c.contentSize.height / 2), dinosaur1_c.contentSize.width, dinosaur1_c.contentSize.height);

    if( CGRectContainsPoint(dinosaur1, touchLocation) )
    {
        CCLOG(@"Tapped Dinosaur1_c!");
        PLAYSOUNDEFFECT(PUZZLE_SKULL);

        //  Code to disable touches??
        //  Tried to resize CGRect in here to (0, 0, 1, 1) to get it away from the original sprite, but did not work.  Still was able to tap on CGRect.
        //  Tried [[CCTouchDispatcher sharedDispatcher] setDispatchEvents:NO];, but disables ALL the sprites instead of just this one.

    }
}

いことでタップのスプライトに再生することができますの音しかできなどを無効にするにはCGRectです。しかし異なる方法と、コードです。そのアイデアはどマッサージやエクササイズをお願いいたします。

役に立ちましたか?

解決 2

Okい解決の問題です。場合にも、英語上級者の方にお尋ねしたい設-(BOOL)isTapped私のヘッダファイルに設定していません私のinit方法です。

私はチェックのための衝突にtouchpointのCGRectもチェックがisTapped!= あり(意味でセンタータップしています。その場合、全ての行動としては、通常は設定isTapped=あります。今までスキップ以上の時にをタップす。以下が私のコードをビット間*'s

.h file:

BOOL isTapped;

と出ます。mファイル:

.m:

-(id)init
{
  isTapped = NO;
  // Rest of init method.
}

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchLocation = [touch locationInView:[touch view]];
    touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
    touchLocation = [self convertToNodeSpace:touchLocation];

    dinosaur1 = CGRectMake(dinosaur1_c.position.x - (dinosaur1_c.contentSize.width / 2), dinosaur1_c.position.y - (dinosaur1_c.contentSize.height / 2), dinosaur1_c.contentSize.width, dinosaur1_c.contentSize.height);

    if( CGRectContainsPoint(dinosaur1, touchLocation) **&& isTapped != YES**)
    {
        CCLOG(@"Tapped Dinosaur1_c!");
        PLAYSOUNDEFFECT(PUZZLE_SKULL);

        **isTapped = YES;**
    }
    else
    {
        CCLog(@"Already Tapped!");
    }
}

感謝!

他のヒント

このままでもありました。

- (void)selectSpriteForTouch:(CGPoint)touchLocation {
 for (CCSprite *sprite in _projectiles) {

if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) {

    NSLog(@"sprite was touched");


    [sprite.parent removeChild:sprite cleanup:YES];

    [self removeChild:sprite.parent cleanup:YES];

}
  }    }

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
[self selectSpriteForTouch:touchLocation];
NSLog(@"touch was _");
return TRUE;  }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top