Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ccp & cpv - function difference & full form of cocoa

I have following code in my Application.

I am new to game development in 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 & cpv? ( I think it is for setting the layer's position, But I am not sure. So I am Asking)

Sagar

like image 655
Sagar Kothari Avatar asked Jan 24 '23 03:01

Sagar Kothari


2 Answers

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

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

position is a property of the Label object, which probably sets the position on the screen to the point created by ccp(). I don't know which corner is being used as a reference point (center/top-left/bottom-left?) as I've never used COCOS so please try that yourself.

Good luck

like image 96
Joost Avatar answered Jan 26 '23 05:01

Joost


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;
}
like image 20
nall Avatar answered Jan 26 '23 06:01

nall