2011年7月31日 星期日

內存管理筆記

retainCount 是 objective-c  內存管理的唯一依據.  release 後自動  retainCount 減 1 ,  到 0 時  對象 的dealloc 會被觸發。
     所以永遠不該呼叫 對象的 dealloc 方法

 
1,alloc, allocWithZone,new(帶初始化)
   
為對象分配內存,retainCount為“1”,並返回此實例
2,release
   
retainCount 減“1”,減到“0”時調用此對象的dealloc方法
3,retain
   
retainCount 加“1”
4,copy,mutableCopy
   
複製一個實例,retainCount數為“1”,返回此實例。所得到的對像是與其它上下文無關的,獨立的對象(乾淨對象)。
5,autorelease
   
在當前上下​​文的AutoreleasePool棧頂的autoreleasePool實例添加此對象,由於它的引入使Objective-C(非GC管理環境)由全手動內存管理上升到半自動化。


詳細參考文章:參考文章

2011年7月7日 星期四

CCLayer CCFadeOut unrecognized selector sent to instance !!~~~~

//目前使用的是 cocos2d 2.0 rc2 版
//
//在CCLayer 淡出效果時
[self runAction:[CCFadeOut actionWithDuration:0.8f]];
//會出現
[classXX setOpacity:]: unrecognized selector sent to instance 0xXXXXXXX !!

似呼有被回呼某 selector
所以必順實做 setOpacity 讓他變更

// Set the opacity of all of our children that support it
-(void) setOpacity: (GLubyte) opacity
{
for( CCNode *node in [self children] )
{
if( [node conformsToProtocol:@protocol( CCRGBAProtocol)] )
{
[(id) node setOpacity: opacity];
}
}
}

2011年7月5日 星期二

限定只有某CCLayer 觸發 touch

網路上片斷 +試驗
原理還沒詳細研究~先記錄囉~

//================================================================
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES];
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{

return YES;
}