Twitter Weekly Updates for 2012-02-19

  • OOP 에 아주 조금 익숙해 지고 있다 #
  • 외부적인 문제로 단골 카페를 잃은 것 같다 #
  • 어렸을때 동네 꼬마들의 놀이에서도 그랬던 것 같은데, 보드게임 같은 것을 만들면서 가장 어려운 건 승리조건인가보다 #

Powered by Twitter Tools

NSMutableArray : writeToFile / arrayWithContentsOfFile Example

[code language=”objc”]

NSMutableArray *a = [[NSMutableArray alloc] init];

[a addObject:@"123166"];
[a addObject:@"122377"];
[a addObject:@"123188"];
[a addObject:@"123199"];
[a addObject:@"123100"];

for (NSString *ss in a)
{
NSLog(@"%@", ss);
}

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"example.dat"];

[a writeToFile:fileName atomically:YES];

//

NSMutableArray *aa = [NSMutableArray arrayWithContentsOfFile:fileName];
NSLog(@"array count %d", [aa count]);

for (NSString *ss in aa)
{
NSLog(@"result:%@", ss);
}

[/code]

cocos2d custom CCSprite Class Example

EnemySprite.h

[code language=”objc”]
#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface EnemySprite : CCSprite {
int healthpoint;

CCSprite *shadow;
}
@property (readwrite) int hp; // <-
@property (nonatomic, retain) CCSprite *shadow; // <-

@end
[/code]

EnemySprite.m

[code language=”objc”]
#import &quot;EnemySprite.h&quot;

@implementation EnemySprite
@synthesize hp; // <-
@synthesize shadow; // <-

-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect
{
if( (self=[super initWithTexture:texture rect:rect]))
{
}
return self;
}
@end
[/code]

scene_blahblah.m
[code language=”objc”]
#import "EnemySprite.h"

EnemySprite *ep = [EnemySprite spriteWithFile:@&quot;redbar_20x2.png&quot;];
[/code]