首先遇到在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) ));//加上EaseInOut
chessNode->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繼承 那麼無法從 高層類 向基層類轉換的
後面翻譯的時候,忘記在這邊寫了。。。。以後補上