yeah,
I didn't create a class yet because i've already tried and i don't know how to make a class of CCSprite and add a faceUp & faceDown property to the class itself. so i've created 26 cards, 26 Booleans that tells me witch card is up and witch not.
each card has a tag number, they are all different( i don't know if i can have 2 sprites with the same tag )
I sketched the logic of the game on paper but i'm stuck when it comes to controlling if a pair is flipped if not { turn them faceDown again }.
i'm using ccTime to check constantly if a pair is flipped, but when it's not the cards starts flickering and the game crashes.
-(void)update:(ccTime)dt{
if (allAnimationsDidFinished && cardTouchCount==2) {
if (firstSprite == 1 && secondSprite == 24) {
[[SimpleAudioEngine sharedEngine] playEffect:@"bing.caf"];
[self removeChild:card01 cleanup:YES];
[self removeChild:card24 cleanup:YES];
allAnimationsDidFinished = NO;
cardTouchCount = 0;
isFaceUp1 = NO;
isFaceUp24 = NO;
}else {
id flipCardBack = [CCSequence actions: [CCOrbitCamera actionWithDuration:0.35 radius:1 deltaRadius:1 angleZ:270.0
deltaAngleZ:90.0 angleX:0.0 deltaAngleX:0.0],
[CCCallFunc actionWithTarget:self selector:@selector(hideSuits)],
[CCOrbitCamera actionWithDuration:0.35 radius:1 deltaRadius:1 angleZ:0.0
deltaAngleZ:90.0 angleX:0.0 deltaAngleX:0.0], [CCCallFunc actionWithTarget:self selector:@selector(cardFlippedBack)],nil];
if (isFaceUp1==YES) {
[card01 runAction:flipCardBack];
}}}
}
if I choose the right pair it works just fine but if choose the wrong one it crashes...
i'm using a NSMutableArray for touches and it works fine,
-(void)selectSpriteForTouch:(CGPoint)touchLocation{
newSprite = nil;
for (CCSprite *sprite in touchableCards) {
if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) {
newSprite = sprite;
if (cardTouchCount==0) {
firstSprite = newSprite.tag;
}else if (cardTouchCount == 1) {
secondSprite = newSprite.tag;
}
If you want the hole project i can post it.
Any help is welcome!
Thanks !