22 Nov 2012
是指两个物体每条边分别垂直于该轴,如两物体的投影全部重叠则为碰撞,否则没碰撞。
2.1 投影公式
投影公式:
顶点:(vx, vy)
轴 :(ax, ay)
顶点的投影:(x, y)
x = (vx * ax + vy * ay) / (ax * ax + ay * ay) * ax
y = (vx * ax + vy * ay) / (ax * ax + ay * ay) * ay
优化程序,可以省略(ax * ax + ay * ay),假如为1
x = (vx * ax + vy * ay) * ax
y = (vx * ax + vy * ay) * ay
顶点的投影的向量位置公式:
d = (x * ax + y * ay)
2.2 坐标旋转公式
// angle : 旋转角度
// origin: 原点坐标
// point : 要旋转的坐标
// 弧度
float radian = angle * 3.1415926 / 180.0f;
// 旋转后的x坐标
float x = (point.x - origin.x) * cosf(radian) + (point.y - origin.y) * sinf(radian);
// 旋转后的y坐标
float y = (point.y - origin.y) * cosf(radian) - (point.x - origin.x) * sinf(radian);
16 Nov 2012
详细官方教程: "https://help.github.com/articles/fork-a-repo":https://help.github.com/articles/fork-a-repo
$ git clone git@github.com:linguofeng/cocos2d-x.git
$ git remote -v // 查看当前远程版本库
$ git remote add cocos2d-x git://github.com/cocos2d/cocos2d-x.git // 添加原始版本库
$ git fetch cocos2d-x // 获取原始版本库的更新
$ git merge cocos2d-x/master // 合并原始版本库的代码到当前版本库中,合并前确保当前分支是master
$ git fetch cocos2d-x // 获取原始版本库最新的代码
$ git merge cocos2d-x/master // 提交自己的前先合并最新原始版本库中的代码
$ git push origin master // 提交代码到自己的版本库
详细官方教程: "https://help.github.com/articles/using-pull-requests":https://help.github.com/articles/using-pull-requests
15 Nov 2012
CCUserDefault::sharedUserDefault()->setStringForKey("string", "value");
CCUserDefault::sharedUserDefault()->setIntegerForKey("integer", 10);
CCUserDefault::sharedUserDefault()->setFloatForKey("float", 2.3f);
CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.4);
CCUserDefault::sharedUserDefault()->setBoolForKey("bool", true);
CCUserDefault::sharedUserDefault()->flush();
string ret = CCUserDefault::sharedUserDefault()->getStringForKey("string");
double d = CCUserDefault::sharedUserDefault()->getDoubleForKey("double");
int i = CCUserDefault::sharedUserDefault()->getIntegerForKey("integer");
float f = CCUserDefault::sharedUserDefault()->getFloatForKey("float");
bool b = CCUserDefault::sharedUserDefault()->getBoolForKey("bool");
15 Nov 2012
注:本api基于Cocos2d-x 0.13版本
CCSprite * sprite = CCSprite::spriteWithFile("file");
// spriteWithFile("file", CCRectMake(x, y, width, height));
// spriteWithTexture(texture, CCRectMake(x, y, width, height));
// spriteWithSpriteFrame(frame, CCRectMake(x, y, width, height));
// spriteWithSpriteFrameName("file.png");
sprite->setPosition(ccp(x, y)); // 精灵的位置
sprite->setScaleX(1.0f); // 精灵的缩放
sprite->setColor(ccc3(r, g, b)); // 精灵的颜色
sprite->setAnchorPoint(CCPointZero); // 设置精灵的原点为左下角,默认为中心
sprite->setFlipX(true); // x轴反转
sprite->setFlipY(true); // y轴反转
CCSpriteBatchNode * batch = CCSpriteBatchNode::batchNodeWithFile("file");
// batchNodeWithFile("file", capacity);
// CCRectMake(x, y, width, height) 表示从节点中获取某个节点
CCSprite * sprite = CCSprite::spriteWithTexture(batch->getTexture(), CCRectMake(x, y, width, height));
batch->addChild(sprite, 0);
batch->reorderChild(sprite, 3); // 重新排序
CCSpriteFrameCache * cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("file.plist");
cache->addSpriteFramesWithFile("file.plist", "file.png");
CCSprite * sprite = CCSprite::spriteWithSpriteFrameName("plist中定义的名称");
cache->removeSpriteFramesFromFile("file.plist");
cache->removeUnusedSpriteFrames(); // 删除没被使用的资料
CCTexture2D * texture = CCTextureCache::sharedTextureCache()->addImage("file.png");
CCSpriteFrame * frame = CCSpriteFrame::frameWithTexture(texture, CCRectMake(x, y, width, height));
CCSprite * sprite = sprite::spriteWithSpriteFrame(frame);
15 Nov 2012
注:本api基于Cocos2d-x 0.13版本
#if CC_ENABLE_PROFILERS
CCProfilingTimer * timer = CCProfiler::timerWithName("none", this)
#endif
#if CC_ENABLE_PROFILERS
CCProfiler::releaseTimer(timer);
timer = NULL;
#endif
#if CC_ENABLE_PROFILERS
CCProfilingBeginTimingBlock(timer);
#endif
#if CC_ENABLE_PROFILERS
CCProfilingEndTimingBlock(timer)
#endif