2009-10-01 15 views
4

我的應用程序中有以下代碼。ccp&cpv - 功能差異和可可的完整形式

我是新來的使用COCOS的iPhone遊戲開發。

Sprite *bg=[Sprite spriteWithFile:@"menu.png"]; 
    [bg setPosition:ccp(240,160)]; 
    [self addChild:bg z:0]; 
    [self addChild:[GameLayer node] z:1]; 
} 
return self; 

}

@end 
@implementation GameLayer 
-(id)init{ 
    if(self=[super init]){ 
     Label *test=[Label labelWithString:@"Hello World" fontName:@"Helvetica" fontSize:24]; 
     test.position=cpv(160, 240); 
     test.visible=YES; 
     [self addChild:test]; 
    } 
    return self; 
} 

什麼是中共& CPV的功能? (我認爲這是用於設置圖層的位置,但我不知道,所以我問)

薩加爾

回答

4

從源代碼:

CGPointExtension.h

#define ccp(__X__,__Y__) CGPointMake(__X__,__Y__) 

cpVect.h

#define cpVect CGPoint 
static inline cpVect cpv(const cpFloat x, const cpFloat y) 
{ 
     cpVect v = {x, y}; 
     return v; 
} 
5

中共是COCOS定義很容易地創建一個CGPoint一個簡單的宏。因此,這無非只是一個點(x,y座標)更多的是定義爲:

#define ccp(__X__,__Y__) CGPointMake(__X__,__Y__) 

位置是標籤的對象,這可能將在屏幕上的位置由創建點的屬性ccp()。我不知道哪個角落被用作參考點(中心/左上角/左下角?),因爲我從未使用過COCOS,所以請自己嘗試一下。

好運