Skip to content

Instantly share code, notes, and snippets.

@alinradut
Created April 17, 2011 18:46
Show Gist options
  • Save alinradut/924345 to your computer and use it in GitHub Desktop.
Save alinradut/924345 to your computer and use it in GitHub Desktop.
- (void)achievementUnlocked:(NSString *)achievement {
[achievements_ addObject:achievement];
// lazy load the achievements layer
if (!achievementLayer_) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
// instantiate the layer
achievementLayer_ = [[CCLayer alloc] init];
achievementLayer_.anchorPoint = ccp(0,0);
achievementLayer_.position = ccp(winSize.width/2, winSize.height - 60);
// create the achievement badge sprite
CCSprite *badge = [CCSprite spriteWithSpriteFrameName:@"btn-achievement.png"];
badge.tag = 1;
[achievementLayer_ addChild:badge];
// create the achievement label
CCLabelTTF *label = [CCLabelTTF labelWithString:@"" fontName:@"Chalkduster.ttf" fontSize:18];
label.color = ccc3(187,54,54);
label.tag = 2;
[achievementLayer_ addChild:label];
[self addChild:achievementLayer_];
[achievementLayer_ release];
}
// make the achievement layer really really small
achievementLayer_.scale = 0.01;
// update the achievement text
[(CCLabelTTF *)[achievementLayer_ getChildByTag:2] setString:achievement];
achievementLayer_.visible = YES;
// compute the size of the text
CGSize size = [achievement sizeWithFont:[UIFont fontWithName:@"Chalkduster" size:18]];
// move the achievements badge to the left
[achievementLayer_ getChildByTag:1].position = ccp(-size.width/2 - 12, 0);
// animate the achievements layer and give it a bouncy feeling
[achievementLayer_ runAction:[CCSequence actions:
// scale from 0.01 to 1.60
[CCScaleTo actionWithDuration:.2 scale:1.6],
// scale from 1.60 to 0.80
[CCScaleTo actionWithDuration:.1 scale:0.8],
// scale from 0.80 to 1.00
[CCScaleTo actionWithDuration:.1 scale:1],nil]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment