如何禁用触摸后的CCRect/sprite触摸?如何在一次触摸后禁用CGRect/Sprite上的触摸
我在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。我已经尝试了上面代码中评论的不同方法。任何想法或提示都表示赞赏!
您是否尝试在'ccTouchBegan:withEvent:'上返回'NO'? – 2012-02-22 02:50:32
解决了!只要stackoverflow允许我发布我的解决方案。我几乎在我的init方法中设置了一个 - (BOOL)已跳到NO,并且在检查它的什么时候被点击时,我也检查它是否为!= YES。在这种方法中,我设置为YES,所以下一次出现时,它会通过。 – rizzlerazzle 2012-02-22 02:59:36