Ccp & cpv - function difference and full form of cocoa

I have the following code in my application.

I am new to developing games on iPhone using COCOS.

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; } 

What is the function of ccp and cpv? (I think this is for setting the position of the layer, but I'm not sure. Therefore, I ask)

Sagar

+4
source share
2 answers

From the source code:

From CGPointExtension.h

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

From cpVect.h

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

ccp is a simple macro defined by COCOS to easily create CGPoint. So this is nothing more than a simple point (x, y coordinate). It is defined as:

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

position is a property of the Label that probably sets the position on the screen to the point created by ccp() . I don’t know which angle is used as a control point (center / upper left / lower left?), Since I never used COCOS, so please try it yourself.

Good luck.

+5
source

All Articles