1 CCTMXObjectGroup的使用方法

为了取以下内容:

操作代码如下:

T27TileMapObject.h

#ifndef
__T27TileMapObject_H__

#define
__T27TileMapObject_H__

#include
"cocos2d.h"

#include
"cocos-ext.h"

#include
"TBack.h"

USING_NS_CC;

USING_NS_CC_EXT;

//格子地图对象层

class
T27TileMapObject :public
TBack

{

public:

CREATE_FUNC(T27TileMapObject);

bool
init();

static
CCScene* scene();

};

#endif

T27TileMapObject.cpp

#include
"T27TileMapObject.h"

CCScene*
T27TileMapObject::scene()

{

CCScene*
scene = CCScene::create();

T27TileMapObject *
layer = T27TileMapObject::create();

scene->addChild(layer);

return
scene;

}

bool
T27TileMapObject::init()

{

TBack::init();

CCTMXTiledMap *
map = CCTMXTiledMap::create("MarioMap1.tmx");

addChild(map);

//这里的objects是MarioMap1.tmx中的一个key

CCTMXObjectGroup*
objGroup = map->objectGroupNamed("objects");

CCArray*
objs = objGroup->getObjects();

CCObject*
obj;

CCTexture2D*
texture = CCTextureCache::sharedTextureCache()->addImage("Mushroom0.png");

CCSpriteFrame*
frame = CCSpriteFrame::createWithTexture(

texture,
CCRectMake(0,0,texture->getContentSize().width / 4,texture->getContentSize().height));

CCARRAY_FOREACH(objs,
obj)

{

//通过下面的方式获得object中的参数信息

CCDictionary*
dict = (CCDictionary*)obj;

const
CCString* name =
dict->valueForKey("name");

const
CCString* type =
dict->valueForKey("type");

const
CCString* x = dict->valueForKey("x");

const
CCString* y = dict->valueForKey("y");

if (type->m_sString ==
"mushroom")

{

//创建一个蘑菇怪Mushroom0.png

CCSprite*
sprite = CCSprite::createWithSpriteFrame(frame);

map->addChild(sprite);

sprite->setPosition(ccp(x->intValue(),y->intValue()));

sprite->setZOrder(10000);

}

//如果object对象的名字是Birthday,那么将执行以下的操作

if (type->m_sString ==
"BirthPoint")

{

CCSprite*
sprite = CCSprite::createWithSpriteFrame(frame);

map->addChild(sprite);

sprite->setPosition(ccp(x->intValue(),y->intValue()
- 16));

//如果不设置这一句,马里奥会在山后

sprite->setZOrder(10000);

//设置锚点

sprite->setAnchorPoint(ccp(0,0));

}

}

return
true;

}

运行结果:

2 TileMapObject的使用的更多相关文章

随机推荐

  1. codeforces round #419 E. Karen and Supermarket

    On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a ...

  2. 【bzoj4444 scoi2015】国旗计划

    题目描述 A 国正在开展一项伟大的计划 —— 国旗计划.这项计划的内容是边防战士手举国旗环绕边境线奔袭一圈.这项计划需要多名边防战士以接力的形式共同完成,为此,国土安全局已经挑选了 NN 名优秀的边防 ...

  3. hdu3966 点权模板-树链部分

    Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. python nonloacal

    Python 3 添加了 nonlocal 关键字,把 None.True 和 False 提升为关键字,废弃了 print 和 exec.今天细说下 nonlocal 的用法 nonloacal是最 ...

  5. django rest-framework 3.类 实现restful

    上节提到过,REST框架分别提供了对函数和类的装饰器,之前已经都是通过函数来写视图函数的,现在来尝试使用class 类来实现视图函数 使用基于类编写API视图,允许重用常用的功能,减少代码重复. 一. ...

  6. 如何为分布式系统优雅的更换RPC

    为啥需要更换RPC? 很多小伙伴都遇到过需要为分布式系统调用更换RPC的问题,为什么会遇到这种事呢?其实,在系统搭建初期,需求简单,架构简单,最重要的是请求量也少,所以很多系统都采用快速原型开发模式, ...

  7. 07_Linux目录文件操作命令4解压缩,文件查找_我的Linux之路

    这一节还是一样学习操作目录文件的命令 在这一节,我会讲到解压压缩tar以及zip命令,以及文本查找命令grep tar 打包压缩命令 tar命令可以为linux的文件和目录创建档案 首先要弄清两个概念 ...

  8. ASP.NET Core部署到Windows IIS

    网上已经有许多ASP.NET Core关于Widows IIS部署的文章,在部署到服务器时遇到了一些问题,在这里我就不再对原理进行阐释(复制)了,只写下一些关键环节,想看原理的同学请参考官网,此文章作 ...

  9. Firebird数据库相关操作

    Firebird常用SQL 一.分页写法小例: 1 select first 10 templateid,code,name from template ; 2 select first 10 ski ...

  10. PHP 常用函数集合

    PHP is_numeric() 函数 由 陈 创建, 最后一次修改 2016-12-02 定义和用法 is_numeric() - 检测变量是否为数字或数字字符串 语法 bool is_numeri ...