oc 翻译到cocos2dx 过程中的知识点
来源:互联网 发布:头戴耳机推荐 知乎 编辑:程序博客网 时间:2024/06/11 20:48
首先遇到在oc里面的 (声明下面在写的时候没有立马测试因为没翻译全边翻译边写博客的)
- clearColor
[UIColor clearColor]
在cocos里面没有
查阅下oc资料发现
+ (UIColor *)clearColor; // 0.0 white, 0.0 alpha
而cocos2dx
const Color4B Color4B::WHITE (255, 255, 255, 255);
于是大胆猜测
#define Color4BClearColor Color4B(255, 255, 255, 0)
- backgroundColor
在oc里面有背景颜色 backgroundColor
我在cocos里面用LayerColor 但是这个LayerColor 我没有发现可以改变颜色的方法很头疼 我就重新生成算了
- NSArray NSMutableArray replaceObjectAtIndex
在oc里面遇到个要返回NSArray并且在方法内使用NSMutableArray
在cocos里面
我开始想使用 int[] 来返回 但是后来发现c++不允许使用int[] 当做函数返回值 只能是int* 我就不爽了
后来查阅了list vector 最后决定使用vector
代码如下直接贴出来算了
vector<int> ***::getRecentNodesTagOftheNode(){ vector<int> recentNodesList {-9,-8,-7,-1,1,7,8,9}; if (0 == tag % 8) { int rightIndexs[] = {2,4,7}; for (int i=0; i<3; ++i) { recentNodesList[rightIndexs[i]] = -1; } } *** return recentNodesList;}
- 枚举 我喜欢使用枚举不喜欢使用 #define
使用枚举和使用#define在代码上有时候看起来一样的 但是#define可能会定义重复 并且影响编译速度 不过#define可以定义很多东西 如果只是用来区别东西的数字不需要用#define
比如我在写五子棋的时候活四,活三,,,等算他们的价值的时候不必要使用#define
又比如要定义一些不能重复的tag标记起来 用#define或许还会定义重复
typedef NS_ENUM (NSInteger,GAMESTATE){ GAMEREADY = 0, GAMEING, GAMEOVER};
->
typedef enum{ GAMEREADY = 0, GAMEING, GAMEOVER}GAMESTATE;
YES NO true false 就没啥好说的 如果不习惯可以#define下 还有就是nil 在这里可以使用 nullptr NULL 不过没有具体测试
在oc里面有一个根据tag获取view的
[view viewWithTag:nTag]
->
node->getChildByTag(nTag)
- isKindOfClass
tempNode isKindOfClass:[** class]
typeid( i ) == typeid( int )
- UIButton transform
node.transform = CGAffineTransformMakeScale(0.9, 0.9);
意思好像就是view的缩放
[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationRepeatCount:MAXFLOAT]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationRepeatAutoreverses:YES]; node.transform = CGAffineTransformMakeScale(0.9, 0.9); [UIView commitAnimations];
->
chessNode->runAction(ScaleTo::create(0.5, 0.9, 0.9));node->chessNode->runAction(RepeatForever::create( ScaleTo::create(0, 1, 1) ));//加上重复runAction(RepeatForever::create( EaseInOut::create(ScaleTo::create(0, 1, 1), 1) ));//加上EaseInOutchessNode->runAction(ScaleTo::create(0.5, 0.9));//或者这个但是为了匹配上面的两个0.9
哇好像更简洁了当然oc那边也有简洁的
[UIView animateWithDuration:0 animations:^{ node.transform = CGAffineTransformMakeScale(1, 1);}];
- 随机数
在oc中有
u_int32_t arc4random(void);
std::rand()
- valueForKeyPath max.self
[changeSumList indexOfObject:[changeSumList valueForKeyPath:@"@max.self"]]//意思是最大值所在的位置
我这里就随便弄一段搓代码代替了
int maxOfIndex = 0; for (int i =1; i<changeSumList.size(); i++) { if (changeSumList[maxOfIndex] < changeSumList[i]) { maxOfIndex = i; } }
- (void)drawRect:(CGRect)rect 绘制view
这里用到的基本上是画线
CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(ctx, (i == 0 || i==kSize)?5:2.0); CGContextSetStrokeColorWithColor(ctx, [[UIColor purpleColor] CGColor]); CGContextMoveToPoint(ctx, 10,10+kNodeWidth*i); CGContextAddLineToPoint(ctx, 10+kNodeWidth*kSize, 10+kNodeWidth*i); CGContextStrokePath(ctx);*****
DrawNode* drawNode = DrawNode::create();drawNode->....addChild(drawNode);
- c++ 继承 如果不是public继承 那么无法从 高层类 向基层类转换的
后面翻译的时候,忘记在这边写了。。。。以后补上
0 0
- oc 翻译到cocos2dx 过程中的知识点
- OC中的零碎知识点
- OC中的小知识点
- OC中的几个基础知识点
- OC学习中的一些知识点(自用)
- OC---知识点
- OC知识点
- oc知识点
- cocos2dx+lua打包Android过程中的问题
- 集成cocos2dx中的CHttpClient到lua中
- 集成cocos2dx中的CHttpClient到lua中
- OC学习过程中的一些总结
- OC中的NSArrAY。NSString。NSDictionary 。NSSet小知识点
- iOS学习中有关的oc中的所有的知识点
- ios开发过程中的小知识点
- Android开发过程中的几个小知识点
- iOS 在开发过程中的 零碎知识点
- cocos2dx-3.3 导出自定义类到 lua 过程详解
- iOS沙盒路径的查看和使用
- ubuntu12.04向MATLAB/R2014b/toolbox里添加工具箱
- linux内核架构-中断处理机制
- ARP攻击实战之WinArpAttacker
- Win+R+快捷键
- oc 翻译到cocos2dx 过程中的知识点
- OpenCv中混合高斯模型的实现
- 黑马程序员——java基础——Java中的常量及变量
- 谈谈数据库的ACID
- Objective-C中的instancetype和id区别
- Linux下安装maven
- C语言 异步回调
- Maven搭建springmvc+spring+hibernate+mysql框架
- SWT背景图的平铺与拉伸