taoru's memo

Objective-c,cocos2d,など開発についてのメモ(andoroidも少しだけ)

CCTouchDispatcher と isRelativeAnchorPoint が非推奨だった

ブログなどで紹介されているクラスやメソッドが、Cocos2d 2.xでは非推奨になっていることがよくある。
ソースを追えば、現在の推奨メソッドが発見できたりする。

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];

↑Cocos2d 2.x では非推奨

↓こうする

[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];


CCLayerに対してアンカーポイントを設定したいときはignoreAnchorPointForPositionを使うようにする。

CCLayer *layer = [CCLayer alloc] init];
layer.isRelativeAnchorPoint = YES;

↑Cocos2d 2.x では非推奨
[layer setIsRelativeAnchorPoint:YES] でも非推奨(↑と同じです)

↓こうする

CCLayer *layer = [CCLayer alloc] init];
[layer setIsIgnoreAnchorPointForPosition:NO];


isRelativeAnchorPointと、ignoreAnchorPointForPosition は振る舞いが逆なので注意

QLOOKアクセス解析