태그 : cocoa
2010/09/07 Cocoa 아이폰 개발 - Custom Font 사용하기 [5]
2010/08/25 코코아 아이폰 개발 - 세이브 화일 저장하기
쓰레드를 이용해서 자연스러운 로딩화면을 보여주면서
백그라운드로 로딩하는데는 여러가지 방법이 있겠지만,
cocos2d 에서 이용할 수 있는 간단한 방법 중엔 이런게 있네요.
원문 링크 중의 어느 댓글을 참고해서 테스트를 해보면..
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
.....
// app뜨면 바로 로딩씬을 불러와서 실행~
loadingScene = [[LoadingScene alloc] init];
[[CCDirector sharedDirector] runWithScene: loadingScene];
// 쓰레드 생성해서 로딩하기~
NSThread* thread = [[[NSThread alloc] initWithTarget:self selector:@selector(loadingProc) object:nil] autorelease];
[thread start];
}
- (void)loadingSceneProc {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// 이게 핵심 코드 없으면 텍스쳐 다 깨지고 난리납니다;
// 뭐하자는 얘기인지 감만 올 뿐이죠 =_=;;
EAGLContext *k_context = [[[EAGLContext alloc]
initWithAPI :kEAGLRenderingAPIOpenGLES1
sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]] autorelease];
[EAGLContext setCurrentContext:k_context];
// 여기서 필요한 것들을 백그라운드로 로딩!
// 실제로 사용할 MainScene에 로딩할게 잔뜩있다고 치고.. 생성해서 로딩~
mainScene = [[MainScene alloc] init];
// 이게 혹시(!) thread-safe하지 않으면 다른 방식으로 notification 처리 필요~
[[CCDirector sharedDirector] replaceScene:mainScene];
[pool release];
}
# by | 2010/10/31 03:03 | 개발 | 트랙백 | 덧글(1)


// 등록된 폰트 이름 보기
NSArray* tempFonts = [UIFont familyNames];
for(NSString* aFont in tempFonts)
NSLog(aFont);
# by | 2010/09/07 22:53 | 개발 | 트랙백(1) | 덧글(5)
+(void)saveToFile:(NSString*)filename object:(id)root
{
NSString *path = [self getPath:filename];
// root 부터 줄줄이 하위객체를 다 돌면서 path화일에 저장하게 됩니다.
BOOL saved=[NSKeyedArchiver archiveRootObject:root toFile:path];
if (saved){
NSLog(@"saved");
} else {
NSLog(@"not saved");
};
}
+(id)loadFromFile:(NSString*)filename
{
NSString *path = [self getPath:filename];
// path화일을 읽어서 적절한 객체를 생성해서 넘겨줍니다.
id obj = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
return obj;
}
@interface MyObject : NSObject<NSCoding> {
....
int score;
MySubObject* subObj;
int intArray[INT_ARRAY_MAX];
}
...
@end
@implementation MyObject
- (id) initWithCoder: (NSCoder *)coder
{
if ((self = [super init]))
{
score = [coder decodeIntForKey:@"score"];
self.subObj = [coder decodeObjectForKey:@"subObj"];
[coder decodeArrayOfObjCType:@encode(int) count:INT_ARRAY_MAX at:(void *)intArray];
}
}
- (void) encodeWithCoder: (NSCoder *)coder
{
[coder encodeInt:score forKey:@"score"];
[coder encodeObject:subObj forKey:@"subObj"]; // MySubObject도 NSCoding구현 필수!
[coder encodeArrayOfObjCType:@encode(int) count:INT_ARRAY_MAX at:(const void*)intArray];
}
@end
# by | 2010/08/25 22:15 | 개발 | 트랙백 | 덧글(0)
◀ 이전 페이지 다음 페이지 ▶