2 TileMapObject的使用
来源:互联网 发布:守望先锋伤害数据 编辑:程序博客网 时间:2024/05/25 12:23
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的使用
- PowerDesigner的使用2
- jar的使用(2)
- webbrowser 的使用2
- dbms_sql的使用 2
- cursor的使用 2
- ListView的使用2
- 定时器的使用2
- JDBC的使用(2)
- JQuery 的使用(2)
- VBO的使用2
- uploadify3.2的使用
- 2>&1的使用
- adapter的使用2
- 示波器的使用2
- awk的使用(2)
- sed的使用(2)
- 2、搜索引擎的使用
- Android sqlite数据库操作通用框架AHibernate(二)-CRUD ...
- 一个有意思的递归-字符串
- 转载文章
- 关于iOS UITableView 数据源数组加载完成之后,滑动时出现cell为空的问题解决笔记
- 位运算举例
- 2 TileMapObject的使用
- Sum Root to Leaf Numbers
- Why your Android NDK breakpoints might fail and how to fix them
- MySQL、SQLServer2000(及SQLServer2005)和ORCALE三种数据库实现分页查询的方法
- struct实现拥有可变大小的数组
- 个人总结的一个中高级Java开发工程师或架构师需要掌握的一些技能
- hdu- 2602 Bone Collector
- Eclipse+CDT+GDB调试android NDK程序
- 汇编语言入门配置