1.字符串 与 数据结构互转

CCPoint:  CCPointFromString(); {x, y}
CCSize: CCSizeFromString(); {w, h}
CCRect: CCSizeFromString(); {x, y, w, h}

2.plist文件使用,配置文件使用

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>level1</key>
<dict>
<key>bg_far_scene</key>
<dict>
<key>path</key>
<string>images/far_scene.png</string>
<key>pos</key>
<string>{, }</string>
</dict>
<key>bg_near_scene</key>
<dict>
<key>path</key>
<string>images/near_scene.png</string>
<key>pos</key>
<string>{, }</string>
</dict>
</dict>
</dict>
</plist>
CCDictionary *data = CCDictionarycreateWithContentsOfFile("parm.plist");
data->objectForKey("gravity")

3.触摸拖动变化

ccTouchesMoved
CCPoint diff = touch->getDelta();

4.tile map

CCTMXTiledMap *map = CCTMXTiledMap::create("TileMaps/iso-test-vertexz.tmx");
addChild(map, , kTagTileMap); /* 直接根据位置获取地图上的精灵 */
CCTMXLayer* layer = map->layerNamed("Trees");
m_tamara = layer->tileAt( ccp(,) );//获取的是CCSprite对象
m_tamara->retain(); /* 设置某个点的GID值,GID数字标识图块对应的图片样子 */
layer->setTileGID(1, ccp( x, y ) );
//遮挡排序
// tile height is 64x32 //斜45度
// map size: 30x30
CCPoint p = m_tamara->getPosition();
p = CC_POINT_POINTS_TO_PIXELS(p);
float newZ = -(p.y+) /;
m_tamara->setVertexZ( newZ ); // tile height is 101x81 //正交
// map size: 12x12
CCPoint p = m_tamara->getPosition();
p = CC_POINT_POINTS_TO_PIXELS(p);
m_tamara->setVertexZ( -( (p.y+) /) ); //缩小,2秒缩小一半
CCArray* pChildrenArray = map->getChildren();
CCSpriteBatchNode* child = NULL;
CCObject* pObject = NULL;
CCARRAY_FOREACH(pChildrenArray, pObject)
{
child = (CCSpriteBatchNode*)pObject; if(!child)
break; child->getTexture()->setAntiAliasTexParameters();
}
map->runAction( CCScaleBy::create(, 0.5f) );

5.给Scene层抹上底色

CCLayerColor* color = CCLayerColor::create( ccc4(,,,) );
addChild(color, -);

6.动作移动地图

// move map to the center of the screen
CCSize ms = map->getMapSize();
CCSize ts = map->getTileSize();
map->runAction( CCMoveTo::create(1.0f, ccp( -ms.width * ts.width/, -ms.height * ts.height/ )) );

7.动作

CCActionInterval* move = CCMoveBy::create(0.5f, ccp(,));
CCActionInterval* rotate = CCRotateBy::create(, );
CCActionInterval* scale = CCScaleBy::create(, );
CCActionInterval* opacity = CCFadeOut::create();
CCActionInterval* fadein = CCFadeIn::create();
CCActionInterval* scaleback = CCScaleTo::create(, );
CCActionInstant* finish = CCCallFuncN::create(this, callfuncN_selector(TMXReadWriteTest::removeSprite));
CCSequence* seq0 = CCSequence::create(move, rotate, scale, opacity, fadein, scaleback, finish, NULL); void TMXReadWriteTest::removeSprite(CCNode* sender)
{
////----CCLOG("removing tile: %x", sender);
CCNode* p = ((CCNode*)sender)->getParent(); if (p)
{
p->removeChild((CCNode*)sender, true);
} //////----CCLOG("atlas quantity: %d", p->textureAtlas()->totalQuads());
}

8.对于对象节点

CCTMXTiledMap* map = (CCTMXTiledMap*) getChildByTag(kTagTileMap);
CCTMXObjectGroup* group = map->objectGroupNamed("Object Group 1"); CCArray* objects = group->getObjects();
CCDictionary* dict = NULL;
CCObject* pObj = NULL;
CCARRAY_FOREACH(objects, pObj)
{
dict = (CCDictionary*)pObj; if(!dict)
break;
const char* key = "x";
int x = ((CCString*)dict->objectForKey(key))->intValue();
key = "y";
int y = ((CCString*)dict->objectForKey(key))->intValue();
key = "width";
int width = ((CCString*)dict->objectForKey(key))->intValue();
key = "height";
int height = ((CCString*)dict->objectForKey(key))->intValue(); glLineWidth();
ccDrawLine( ccp((float)x, (float)y), ccp((float)(x+width), (float)y) );
ccDrawLine( ccp((float)(x+width), (float)y), ccp((float)(x+width), (float)(y+height)) );
ccDrawLine( ccp((float)(x+width), (float)(y+height)), ccp((float)x, (float)(y+height)) );
ccDrawLine( ccp((float)x, (float)(y+height)), ccp((float)x, (float)y) );
//获取对象的名字
key = "name";
CCString * str = ((CCString*)dict->objectForKey(key));
glLineWidth();
}

9、弹框提示

CCMessageBox("this is content","title");

10、vs中va功能---自动添加头文件查找

工具->选项->键盘

VAssistX.RefactorAddInclude设置快捷键即可

11、整个游戏速度设置^^!

float multi = 1.0f;
CCDirector::sharedDirector()->getScheduler()->setTimeScale(multi);

12、tile map 绘制的椭圆Object,x,y 表示 坐下交位置 , 中心点 centerX = x + width/2  centerY = y + height/2

cocos2d-x 小技巧的更多相关文章

  1. 前端网络、JavaScript优化以及开发小技巧

    一.网络优化 YSlow有23条规则,中文可以参考这里.这几十条规则最主要是在做消除或减少不必要的网络延迟,将需要传输的数据压缩至最少. 1)合并压缩CSS.JavaScript.图片,静态资源CDN ...

  2. Git小技巧 - 指令别名及使用Beyond Compare作为差异比较工具

    前言 本文主要写给使用命令行来操作Git的用户,用于提高Git使用的效率.至于使用命令还是GUI(Tortoise Git或VS的Git插件)就不在此讨论了,大家根据自己的的喜好选择就好.我个人是比较 ...

  3. 分享两个BPM配置小技巧

    1.小技巧 流程图修改后发布的话版本号会+1,修改次数多了之后可能会导致版本号很高,这个时候可以将流程导出,然后删除对应的流程包再导入,发布数据模型和流程图之后,版本清零 2.小技巧 有的同事入职后使 ...

  4. linux系统维护时的一些小技巧,包括系统挂载新磁盘的方法!可收藏!

    这里发布一些平时所用到的小技巧,不多,不过会持续更新.... 1.需要将history创建硬链接ln 全盘需要备份硬链接 ln /etc/xxx /home/xxx 2.root用户不可以远程 /et ...

  5. JS处理事件小技巧

    今天,就分享一下我自己总结的一些JS的小技巧: ①防止鼠标选中事件 <div class="mask" onselectstart="return false&qu ...

  6. iOS:小技巧(不断更新)

    记录下一些不常用技巧,以防忘记,复制用. 1.获取当前的View在Window的frame: UIWindow * window=[[[UIApplication sharedApplication] ...

  7. css小技巧(1)

    1.-webkit-overflow-scrolling: touch; 解决ios滑动时无缓冲问题 2.::-webkit-scrollbar 设置ios滑动时是否显示滚动条 3.::selecti ...

  8. 最强 Android Studio 使用小技巧和快捷键

    写在前面 本文翻译自 Android Studio Tips by Philippe Breault,一共收集了62个 Android Studio 使用小技巧和快捷键. 根据这些小技巧的使用场景,本 ...

  9. ios开发中的小技巧

    在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIViewal ...

  10. Jquery 小技巧

    [每个程序员都会的35个jQuery的小技巧]收集的35个jQuery的小技巧/代码片段,可以帮你快速开发

随机推荐

  1. POJ 3723 Conscription 最小生成树

    题目链接: 题目 Conscription Time Limit: 1000MS Memory Limit: 65536K 问题描述 Windy has a country, and he wants ...

  2. CSS3属性box-shadow使用教程,css3box-shadow

    CSS3的box-shadow属性可以让我们轻松实现图层阴影效果.我们来实战详解一下这个属性. 1. box-shadow属性的浏览器兼容性先来看一个这个属性的浏览器兼容性: Opera: 不知道是从 ...

  3. Webbrowser 取消下载提示框

    在使用Webbrowser抓取网页信息时,碰到需要下载文件,这时需要用户介入操作,如何避免: 首先引进 [DllImport("urlmon.dll", CharSet = Cha ...

  4. Sublime Text 3 搭建 React.js 开发环境

    sublime有很强的自定义功能,插件库很庞大,针对新语言插件更新很快,配合使用可以快速搭建适配语言的开发环境. 1. babel 支持ES6, React.js, jsx代码高亮,对 JavaScr ...

  5. IOS NSPredicate 查询、搜索

    简述:Cocoa框架中的NSPredicate用于查询,原理和用法都类似于SQL中的where,作用相当于数据库的过滤取. 最常用到的函数 + (NSPredicate *)predicateWith ...

  6. hdu 4497 GCD and LCM

    思路:易知L不能整除G时为0: 将L/G质因数分解,对于其中的因子p,个数为cnt,则至少有一个包含p^cnt,至少有一个数不包含p: 只有一个数包含p^cnt时,有C(3,1); 有2个数包含p^c ...

  7. 【转载】jxl操作excel 字体 背景色 合并单元格 列宽等 .

    package com.email.jav; import java.io.File;import java.io.IOException;import java.net.URL; import jx ...

  8. Openfire 代码部署报错: Variable references non-existent resource:${workspace_loc:openfire_src}

    Variable references non-existent resource:${workspace_loc:openfire_src} -DopenfireHome=“${workspace_ ...

  9. *[hackerrank]Girlfriend & Necklace

    https://www.hackerrank.com/contests/w8/challenges/gneck 有点意思.是DP,最优解包含最优子问题.F(X)=F(X-1)+F(X-3).因为F(X ...

  10. 【memcache缓存专题(2)】memcache安装与命令行使用

    进新公司一个多月了,一直没有时间来更新,后续还是要保持着每日更新的频率 安装 在windows上安装 略(都玩到缓存的程度了,就没必要在windows上捣弄了) 给个参考: http://blog.c ...