well I have a problem with my code :
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView: [myTouch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
CGRect MoveableSpriteRect =CGRectMake(oeuf1.position.x -(oeuf1.contentSize.width/2),oeuf1.position.y-(oeuf1.contentSize.height/2),oeuf1.contentSize.width,oeuf1.contentSize.height);
if (CGRectContainsPoint(MoveableSpriteRect, location)) {
[self removeChild:oeuf1 cleanup: YES];
[self removeChild:ombreOeuf1 cleanup: YES];
}
}
When I touch oeuf1 it disappear like I wanted but then if i touch the screen again my app crash I don’t know why ? how can I solve this please ? thank you . Sorry for my english I’m french :/
The line
CGRect MoveableSpriteRect =CGRectMake(oeuf1.position.x -(oeuf1.contentSize.width/2),oeuf1.position.y-(oeuf1.contentSize.height/2),oeuf1.contentSize.width,oeuf1.contentSize.height);is still referencingoeuf1once it has been removed, and so will cause anEXC_BAD_ACCESSerror. The simplest way to fix it is to declare aBOOLin your header file, and set it toYES/truewhen you removeoeuf1andombreOeuf1. Then if theBOOLis true, don’t runEDIT:
In your
.hfile add:And then change
-touchesBeganto: