본문 바로가기
모바일 개발/iOS

Cocos2d | 기초

by KISCH 2020. 2. 19.
반응형


코코스



헤더파일

1. main.m : 프로그램의 시작

// scene 과  layer 같이 선언 가능

#import "cocos2d.h"

@interface GameOverLayer : CCLayerColor {

    CCLabelTTF *_label;

}

@property (nonatomicretainCCLabelTTF *label;

@end

@interface GameOverScene : CCScene {

    GameOverLayer *_layer;

}

@property (nonatomicretainGameOverLayer *_layer;

@end



메모리


▪︎ alloc : 객체 생성, retain 메시지 보냄(retain 1 증가)

▪︎ copy : retain 메시지 보냄(retain 1 증가)

▪︎ retain : retain 메시지 보냄(retain 1 증가), retainCount가 0이면 소거될 수 있음

@property (... retain) : 자동으로 해제되면 곤란한 오브젝트의 경우 이와 같이 retain 호출


▪︎ dealloc : 인스턴스 변수 소거 

▪︎ release : retainCount 1 감소

▪︎ autorelease : 소거를 잠시 미룸(자동해제 풀 : NSAutoreleasePool 에 등록), 자동 해제(소유자가 없을 경우나 풀이 소거될 때)


▪︎ CCAnimate : autorelease 객체


▪︎ 컨비니언스 메소드 : 나중에 따로 메모리에서 해제하지 않아도 된다.



오디오



#import "SimpleAudioEngine.h"

SimpleAudioEngine *sae;

//init

sae = [SimpleAudioEngine sharedEngine];

sae.effectsVolume = 0.9;   

if (sae != nil) {

[sae preloadBackgroundMusic:@".mp3"];

if (sae.willPlayBackgroundMusic) {

sae.backgroundMusicVolume = 0.5f;

      }

}

[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"xxx.caf"];

// ccTouchesEnded

[[SimpleAudioEngine sharedEngine] playEffect:@"xxx.caf"];





반응형

'모바일 개발 > iOS' 카테고리의 다른 글

Cocos2d | 기타 클래스  (0) 2020.02.20
Cocos2d | CCAction 클래스  (0) 2020.02.20
Cocos2d | 이미지 관련 클래스  (0) 2020.02.20
Cocos2d | CCNode 클래스  (0) 2020.02.20
Cocos2d | 스프라이트 애니메이션  (0) 2020.02.19
Cocos2d | 씬의 흐름  (0) 2020.02.19
iOS | iAP  (0) 2020.02.14
iOS | SDK 기초  (0) 2020.02.14

댓글