Skip to content

Instantly share code, notes, and snippets.

@AsadR
Created August 17, 2011 19:44
Show Gist options
  • Save AsadR/1152418 to your computer and use it in GitHub Desktop.
Save AsadR/1152418 to your computer and use it in GitHub Desktop.
Cocos2D bug
//
// HelloWorldLayer.h
// CocosTest
//
// Created by Asad ur Rehman on 8/10/11.
//
// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"
// HelloWorldLayer
@interface HelloWorldLayer : CCLayer
{
}
// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;
@end
//
// HelloWorldLayer.m
// CocosTest
//
// Created by Asad ur Rehman on 8/10/11.
//
// Import the interfaces
#import "HelloWorldLayer.h"
// HelloWorldLayer implementation
@implementation HelloWorldLayer
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {
// create and initialize a Label
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
// ask director the the window size
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label on the center of the screen
label.position = ccp( size.width /2 , size.height/2 );
// add the label as a child to this Layer
[self addChild: label];
// this will cause an infinite loop of "Sup" being printed to the console
[self runAction:[CCSequence actions:
[CCDelayTime actionWithDuration:0.3f],
[CCCallFunc actionWithTarget:self selector:@selector(sup)],
nil]];
}
return self;
}
- (void)sup {
CCLOG(@"Sup");
NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"Hello", @"World", @"WTF", @"OMG", @"n00b", @"STFU", nil];
for(id a in arr)
if([a isEqual:@"Hello"])
[arr removeObject:a]; /* this will throw an exception */
CCLOG(@"This will never reach here");
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
// in case you have something to dealloc, do it in this method
// in this particular example nothing needs to be released.
// cocos2d will automatically release all the children (Label)
// don't forget to call "super dealloc"
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment