xcode ccp & cpv - 可可的功能差异和完整形式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1505929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ccp & cpv - function difference & full form of cocoa
提问by Sagar R. Kothari
I have following code in my Application.
我的应用程序中有以下代码。
I am new to game development in iPhone using COCOS.
我是使用 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;
}
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)
ccp & cpv 的作用是什么?(我认为是为了设置图层的位置,但我不确定。所以我在问)
Sagar
萨加尔
回答by Joost
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:
ccp 是 COCOS 定义的一个简单的宏,用于轻松创建 CGPoint。所以无非就是一个点(x,y坐标),定义为:
#define ccp(__X__,__Y__) CGPointMake(__X__,__Y__)
positionis 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.
position是 Label 对象的一个属性,它可能将屏幕上的位置设置为由ccp()
. 我不知道哪个角被用作参考点(中心/左上/左下?),因为我从未使用过 COCOS,所以请自己尝试。
Good luck
祝你好运
回答by nall
From the source code:
从源代码:
From CGPointExtension.h
#define ccp(__X__,__Y__) CGPointMake(__X__,__Y__)
From cpVect.h
来自cpVect.h
#define cpVect CGPoint
static inline cpVect cpv(const cpFloat x, const cpFloat y)
{
cpVect v = {x, y};
return v;
}