cocos2d-x 小技巧
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 小技巧的更多相关文章
- 前端网络、JavaScript优化以及开发小技巧
一.网络优化 YSlow有23条规则,中文可以参考这里.这几十条规则最主要是在做消除或减少不必要的网络延迟,将需要传输的数据压缩至最少. 1)合并压缩CSS.JavaScript.图片,静态资源CDN ...
- Git小技巧 - 指令别名及使用Beyond Compare作为差异比较工具
前言 本文主要写给使用命令行来操作Git的用户,用于提高Git使用的效率.至于使用命令还是GUI(Tortoise Git或VS的Git插件)就不在此讨论了,大家根据自己的的喜好选择就好.我个人是比较 ...
- 分享两个BPM配置小技巧
1.小技巧 流程图修改后发布的话版本号会+1,修改次数多了之后可能会导致版本号很高,这个时候可以将流程导出,然后删除对应的流程包再导入,发布数据模型和流程图之后,版本清零 2.小技巧 有的同事入职后使 ...
- linux系统维护时的一些小技巧,包括系统挂载新磁盘的方法!可收藏!
这里发布一些平时所用到的小技巧,不多,不过会持续更新.... 1.需要将history创建硬链接ln 全盘需要备份硬链接 ln /etc/xxx /home/xxx 2.root用户不可以远程 /et ...
- JS处理事件小技巧
今天,就分享一下我自己总结的一些JS的小技巧: ①防止鼠标选中事件 <div class="mask" onselectstart="return false&qu ...
- iOS:小技巧(不断更新)
记录下一些不常用技巧,以防忘记,复制用. 1.获取当前的View在Window的frame: UIWindow * window=[[[UIApplication sharedApplication] ...
- css小技巧(1)
1.-webkit-overflow-scrolling: touch; 解决ios滑动时无缓冲问题 2.::-webkit-scrollbar 设置ios滑动时是否显示滚动条 3.::selecti ...
- 最强 Android Studio 使用小技巧和快捷键
写在前面 本文翻译自 Android Studio Tips by Philippe Breault,一共收集了62个 Android Studio 使用小技巧和快捷键. 根据这些小技巧的使用场景,本 ...
- ios开发中的小技巧
在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIViewal ...
- Jquery 小技巧
[每个程序员都会的35个jQuery的小技巧]收集的35个jQuery的小技巧/代码片段,可以帮你快速开发
随机推荐
- Problem 1016 咒文卷轴 优先队列+前缀和+rmq
题目链接: 题目 Problem 1016 咒文卷轴 Time Limit: 3000 mSec Memory Limit : 131072 KB 问题描述 小Y 是一个魔法师,有一天他获得了一卷神秘 ...
- 0327定时执行--存储过程--dbms_job--dbms_scheduler.create_job
--oracle job 定时执行 存储过程 --建一张测试表 create table Person( name ), sex ) ); / --创建测试的存储过程 create or replac ...
- [转载]Spring Java Based Configuration
@Configuration & @Bean Annotations Annotating a class with the @Configuration indicates that the ...
- Interface Comparator
int compare(T o1, T o2) Compares its two arguments for order. Returns a negative integer, zero, or a ...
- hdu 3661 Assignments(水题的解法)
题目 //最早看了有点云里雾里,看了解析才知道可以很简单的排序过 #include<stdio.h> #include<string.h> #include<algori ...
- Android 虚拟机安装SD卡
在cmd命令行下,进入platform-tools目录下. 1.创建sdcard mksdcard -l mycard 256M E:\android\myCards\mysdcard.img ...
- MySQL.. ERROR! The server quit without updating PID file问题解决
不小心将服务器OS给重启了,再启动数据库的时候,出现了很奇怪的问题 [root@dev run]# service mysql restart ERROR! MySQL server PID file ...
- Intellij 导入play framework 项目
新建一个项目 play new helloworld IshallbeThatIshallbe:~ iamthat$ mkdir temp IshallbeThatIshallbe:~ iamthat ...
- 李洪强iOS开发之【零基础学习iOS开发】【01-前言】02-准备
在上一讲中,介绍了什么是iOS开发.说简单一点,iOS开发,就是开发运行在iPhone或者iPad上的软件.这么一说完,应该有很多人就会产生一些疑惑,比如学习iOS开发是不是一定要买iPhone?需不 ...
- Linux进程管理知识整理
Linux进程管理知识整理 1.进程有哪些状态?什么是进程的可中断等待状态?进程退出后为什么要等待调度器删除其task_struct结构?进程的退出状态有哪些? TASK_RUNNING(可运行状态) ...