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. ●BZOJ 4407 于神之怒加强版

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4407 题解: 莫比乌斯反演 直接套路化式子 $\begin{align*}ANS&= ...

  2. C++Primer学习——函数

    编译器能以任意顺序对形参进行求值 函数的返回类型不能是数组类型和函数类型. 函数开始时为形参分配内存,一旦函数结束,形参也就被销毁了. 如果弄成静态局部变量,那么回到程序终止结束时才被销毁. void ...

  3. [UOJ UNR#1]奇怪的线段树

    来自FallDream的博客,未经允许,请勿转载, 谢谢. 原题可以到UOJ看,传送门 如果存在一个点是白的,却有儿子是黑的,显然无解. 不然的话,只要所有黑色的“黑叶子”节点,即没有黑色的儿子的节点 ...

  4. 【luogu P4005 清华集训2017】小Y和地铁

    题目描述 小 Y 是一个爱好旅行的 OIer.一天,她来到了一个新的城市.由于不熟悉那里的交通系统,她选择了坐地铁. 她发现每条地铁线路可以看成平面上的一条曲线,不同线路的交点处一定会设有 换乘站 . ...

  5. hdu 5465 (树状数组 + 博弈)

    题意:基于矩阵的NIM游戏,求异或和. 思路:在x1,y1 到 x2, y2的异或和 =  A[ x2 ][ y2 ] ^ A[x1-1][ y2 ] ^ A[ x2 ][y1 - 1] ^ A[ x ...

  6. [bzoj4824][Cqoi2017]老C的键盘

    来自FallDream的博客,未经允许,请勿转载,谢谢. 老 C 是个程序员.     作为一个优秀的程序员,老 C 拥有一个别具一格的键盘,据说这样可以大幅提升写程序的速度,还能让写出来的程序在某种 ...

  7. springmvc上传文件方法及注意事项

    本文基于注解的配置,敬请留意  基于注解整合 一.springmvc为我们提供两种上传方式配置: org.springframework.web.multipart.commons.CommonsMu ...

  8. C语言程序设计第六次作业--循环结构(2)

    (一)改错题 序列求和:输入一个正实数eps,计算序列部分和 1 - 1/4 + 1/7 - 1/10 + ... ,精确到最后一项的绝对值小于eps(保留6位小数). 输入输出样例: Input e ...

  9. Access restriction: The type VerticalTextSpinner is not accessible due to restriction on required library........

    查了下竟然是编译器报错,orz了. Access restriction: 访问限制 on required library: 在依赖库(第三方包) 那就简单了,取消限制就好, eclipse的Win ...

  10. Lintcode394 Coins in a Line solution 题解

    [题目描述] There are n coins in a line. Two players take turns to take one or two coins from right side ...