#include "HelloWorldScene.h"
using namespace cocos2d;
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
_tileMap=CCTMXTiledMap::create("map.tmx");
addChild(_tileMap);
/*_background=_tileMap->layerNamed("floor1");*/
CCTMXObjectGroup *objects=_tileMap->objectGroupNamed("hero");//获取对象层
CCDictionary *spawnPoint=objects->objectNamed("pa");//获取对象
const CCString *x=spawnPoint->valueForKey("x");//获取对象的坐标
const CCString *y=spawnPoint->valueForKey("y");
/////////////////////////////////////////////////////
char *tempx=new char[30];//这里的代码将CCString转换为int
char *tempy=new char[30];
memset(tempx,0,30);
memset(tempy,0,30);
sprintf(tempx,x->getCString());
sprintf(tempy,y->getCString());
int px=atoi(tempx);
int py=atoi(tempy);
delete tempx;
delete tempy;
///////////////////////////////////////////////////////////
_player=CCSprite::create("www.png");
_player->setPosition(ccp(px,py));
addChild(_player);
bRet = true;
} while (0);
return bRet;
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
// "close" menu item clicked
CCDirector::sharedDirector()->end();
}
bool HelloWorld::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
return 1;
}
void HelloWorld::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
cocos2d::CCPoint pp=pTouch->getLocation();
if(fabs(pp.x-_player->getPosition().x)>=fabs(pp.y-_player->getPosition().y))
{
if(pp.x>=_player->getPosition().x)
{
_player->setPosition(ccp(_player->getPosition().x+32,_player->getPosition().y));
}
else
{
_player->setPosition(ccp(_player->getPosition().x-32,_player->getPosition().y));
}
}
else
{
if(pp.y>=_player->getPosition().y)
{
_player->setPosition(ccp(_player->getPosition().x,_player->getPosition().y+32));
}
else
{
_player->setPosition(ccp(_player->getPosition().x,_player->getPosition().y-32));
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
【Cocos2d-x游戏引擎开发笔记(13)】Tiled Map Editor(一)
共61个文件
tlog:30个
png:5个
h:4个
5星 · 超过95%的资源 需积分: 47 695 下载量 8 浏览量
2012-12-17
19:11:51
上传
评论 5
收藏 761KB ZIP 举报
温馨提示
【Cocos2d-x游戏引擎开发笔记(13)】Tiled Map Editor(一)
资源推荐
资源详情
资源评论
收起资源包目录
AAATiledMapTest.zip (61个子文件)
AAATiledMapTest
Resources
map.tmx 944B
CloseSelected.png 5KB
www.png 4KB
CloseNormal.png 6KB
tmw_desert_spacing.png 37KB
HelloWorld.png 142KB
theMap.tmx 1KB
proj.win32
res
AAATiledMapTest.ico 47KB
AAATiledMapTest.win32.vcxproj.filters 2KB
Debug.win32
link.7188-cvtres.write.1.tlog 2B
vc100.idb 1.32MB
link.7984.write.1.tlog 2B
link.7188.write.1.tlog 2B
AAATiledMapTest.win32.exe.intermediate.manifest 381B
CL.write.1.tlog 3KB
AAATiledMapTest.win32.lastbuildstate 79B
CL.read.1.tlog 118KB
mt.read.1.tlog 550B
rc.write.1.tlog 954B
link.7828-cvtres.read.1.tlog 2B
link.7676.write.1.tlog 2B
rc.read.1.tlog 3KB
link.7984-cvtres.read.1.tlog 2B
link.7828.read.1.tlog 2B
AppDelegate.obj 91KB
link.7676-cvtres.write.1.tlog 2B
AAATiledMapTest.win32.log 3KB
AAATiledMapTest.res 47KB
mt.command.1.tlog 580B
cl.command.1.tlog 6KB
link-cvtres.read.1.tlog 2B
link.7828-cvtres.write.1.tlog 2B
link.7676-cvtres.read.1.tlog 2B
main.obj 70KB
link.7188-cvtres.read.1.tlog 2B
link.7676.read.1.tlog 2B
link.write.1.tlog 2KB
AAATiledMapTest.win32.exe.embed.manifest 406B
link.7828.write.1.tlog 2B
link.7188.read.1.tlog 2B
link-cvtres.write.1.tlog 2B
link.7984-cvtres.write.1.tlog 2B
link.command.1.tlog 3KB
rc.command.1.tlog 2KB
link.read.1.tlog 5KB
AAATiledMapTest.win32_manifest.rc 244B
AAATiledMapTest.win32.exe.embed.manifest.res 472B
mt.write.1.tlog 550B
HelloWorldScene.obj 163KB
vc100.pdb 636KB
link.7984.read.1.tlog 2B
resource.h 510B
main.cpp 863B
AAATiledMapTest.win32.vcxproj.user 763B
AAATiledMapTest.rc 2KB
main.h 270B
AAATiledMapTest.win32.vcxproj 8KB
Classes
AppDelegate.cpp 1KB
HelloWorldScene.h 918B
AppDelegate.h 960B
HelloWorldScene.cpp 3KB
共 61 条
- 1
临江仙
- 粉丝: 992
- 资源: 37
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页