我的世界籽岷跑酷地图游戏的地图用Tiledmap滚动不流畅

//&Inside&the&HelloWorld&class&declarationCCSprite&*_&//&After&the&class&declaration@property&(nonatomic,&retain)&CCSprite&*
&&&&&&& 修改HelloWorldScene.m
//&Right&after&the&implementation&section@synthesize&player&=&_&//&In&deallocself.player&=&&//&Inside&the&init&method,&after&setting&self.backgroundCCTMXObjectGroup&*objects&=&[_tileMap&objectGroupNamed:@"Objects"];NSAssert(objects&!=&nil,&@"'Objects'&object&group&not&found");NSMutableDictionary&*spawnPoint&=&[objects&objectNamed:@"SpawnPoint"];&&&&&&&&NSAssert(spawnPoint&!=&nil,&@"SpawnPoint&object&not&found");int&x&=&[[spawnPoint&valueForKey:@"x"]&intValue];int&y&=&[[spawnPoint&valueForKey:@"y"]&intValue];&self.player&=&[CCSprite&spriteWithFile:@"Player.png"];_player.position&=&ccp(x,&y);[self&addChild:_player];&[self&setViewpointCenter:_player.position];
&&&&&&&& 我们先花一点时间解释一下object layer和object groups.&&&&&&&&&&&&&&&&
首先,&&&&& 我们通过CCTMXTiledMap对象的objectGroupNamed方法取回object layers.这个方法返回的是一个CCTMXObjectGroup对象.&&&&&&&&&&&&&&&&
接下来,& 调用CCTMXObjectGroup对象的objectNamed方法得到包含一组重要信息的NSMutableDictionary.包括x,y坐标,宽度,高度等.&&&&&&&&&&&&&&&&
在这里,& 我们主要需要的是x,y坐标.我们取得坐标并用它们来设置主角精灵的位置.&&&&&&&&&&&&&&&&
最后,&&&&& 我们要把主角作为视觉中心来显示.现在,添加下面的代码:
-(void)setViewpointCenter:(CGPoint)&position {&&&&CGSize&winSize&=&[[CCDirector&sharedDirector]&winSize];&&&&&int&x&=&MAX(position.x,&winSize.width&/&2);&&&&int&y&=&MAX(position.y,&winSize.height&/&2);&&&&x&=&MIN(x,&(_tileMap.mapSize.width&*&_tileMap.tileSize.width)&&&&&&&&-&winSize.width&/&2);&&&&y&=&MIN(y,&(_tileMap.mapSize.height&*&_tileMap.tileSize.height)&&&&&&&&-&winSize.height/2);&&&&CGPoint&actualPosition&=&ccp(x,&y);&&&&&CGPoint&centerOfView&=&ccp(winSize.width/2,&winSize.height/2);&&&&CGPoint&viewPoint&=&ccpSub(centerOfView,&actualPosition);&&&&self.position&=&viewP&}
&&&&&&& 同样做一下简要的解释.想象这个函数是把视线设置到取景中心.我们可以在地图里设置任何x,y坐标,但是有些坐标不能正确的处理显示.比如,我们不能让显示区域超出地图的边界.否则就会出现空白区.下面的图片更能说明这个问题:&&&&&&&& &&&&&&& 屏幕的宽高计算后,要与显示区域的宽高做相应的适配.我们需要检测屏幕到达地图边缘的情况.&&&&&&&
在cocos2d里本来有一些操控camera(可以理解为可视取景区)的方法,但是使用它可能搞得更复杂.还不如靠直接移动layer里的元素来解决更简单有效.&&&&&&&
继续看下面这张图:&&&&&& &&&&&&& 把整张地图想象为一个大的世界,我们的可见区是其中的一部分.主角实际的坐标并不是世界实际的中心.但是在我们的视觉内,要把主角放在中心点,所以,我们只需要根据主角的坐标便宜,调整世界中心的相对位置就可以了.&&&&&&&
实现的方法是把实际中心与屏幕中心做一个差值,然后把HelloWorld Layer设置到相应的位置.好,现在编译运行,我们会看到小忍者出现在屏幕上.&&&&&&& 使主角移动&&&&&&&
前面进行的都不错,但是到目前为止,我们的小忍者还不会动.&&&&&&&
接下来,我们让小忍者根据用户在屏幕上点击的位置方向来移动(点击屏幕上半部分向上移,依此类推),修改HelloWorldScene.m的代码:
//&Inside&init&methodself.isTouchEnabled&=&YES;&-(void)&registerWithTouchDispatcher{&&&&[[CCTouchDispatcher&sharedDispatcher]&addTargetedDelegate:self&&&&&&&&&&&&priority:0&swallowsTouches:YES];}&-(BOOL)&ccTouchBegan:(UITouch&*)touch&withEvent:(UIEvent&*)event{&&&&return&YES;}&-(void)setPlayerPosition:(CGPoint)position&{&&&&_player.position&=&}&-(void)&ccTouchEnded:(UITouch&*)touch&withEvent:(UIEvent&*)event{&&&&&CGPoint&touchLocation&=&[touch&locationInView:&[touch&view]];&&&&&&&&&&touchLocation&=&[[CCDirector&sharedDirector]&convertToGL:&touchLocation];&&&&touchLocation&=&[self&convertToNodeSpace:touchLocation];&&&&&CGPoint&playerPos&=&_player.&&&&CGPoint&diff&=&ccpSub(touchLocation,&playerPos);&&&&if&(abs(diff.x)&&&abs(diff.y))&{&&&&&&&&if&(diff.x&&&0)&{&&&&&&&&&&&&playerPos.x&+=&_tileMap.tileSize.&&&&&&&&}&else&{&&&&&&&&&&&&playerPos.x&-=&_tileMap.tileSize.&&&&&&&&}&&&&&&&&}&else&{&&&&&&&&if&(diff.y&&&0)&{&&&&&&&&&&&&playerPos.y&+=&_tileMap.tileSize.&&&&&&&&}&else&{&&&&&&&&&&&&playerPos.y&-=&_tileMap.tileSize.&&&&&&&&}&&&&}&&&&&if&(playerPos.x&&=&(_tileMap.mapSize.width&*&_tileMap.tileSize.width)&&&&&&&&&&&playerPos.y&&=&(_tileMap.mapSize.height&*&_tileMap.tileSize.height)&&&&&&&&&&&playerPos.y&&=&0&&&&&&&&&&&playerPos.x&&=&0&)&&&&{&&&&&&&&&&&&[self&setPlayerPosition:playerPos];&&&&}&&&&&[self&setViewpointCenter:_player.position];&}
&&&&&&&& 首先,我们在init方法里设置屏幕接受触摸事件.接下来,覆盖registerWithTouchDispatcher方法来注册我们自己的触摸
事件句柄.这样,ccTouchBegan/ccTouchEnded方法会在触摸发生时回调(单点触摸),并且屏蔽掉ccTouchesBegan
/ccTouchesEnded方法的回调(多点触摸)&&&&&&&&
你可能奇怪,为什么不能使用ccTouchesBegan/ccTouchesEnded方法呢?是的,我们的确可以使用,但是不建议这么做,有两点原因:
你不需要再处理NSSets,事件分发器会帮你处理它们,你会在每次触摸得到独立的回调.
你可以在ccTouchBegan事件返回YES来告知delegate这事你想要的事件,这样你可以在move/ended/cancelled等后续的事件里方便的处理.这比起使用多点触摸要省去很多的工作.
通常,我们会将触摸的位置转换为view坐标系,然后再转换为GL坐标系.这个例子里的小变化,只是调用了一下 [self convertToNodeSpace:touchLocation].&&&&&&&&&
这是因为触摸点给我们的是显示区的坐标,而我们其实已经移动过地图的位置.所以,调用这个方法来得到便宜后的坐标.&&&&&&&&&
接下来,我们要搞清楚触摸点与主角位置的相对关系.然后根据向量的正负关系,决定主角的移动方向.我们相应的调节主角的位置,然后设置屏幕中心到主角上.& &&&&&&&&&
注意: 我们需要做一个安全检查,不要让我们的主角移出了地图.& &&&&&&&&& &&&&&&&&&&好了,现在可以编译运行了,尝试触摸屏幕来移动一下小忍者吧.&&&&&&&&& &&&&&&&
这里是根据这篇教程完成的代码:
&&&&&&& 接下来,我们将学习如何在地图里创建可碰撞(不可穿越)区域,如何使用tile属性,如何使用可碰撞物体和动态修改地图,如何确定你的主角没有产生穿越。
Tiled Maps和碰撞
&&&&&&& 你可能注意到了,上一篇里完成的游戏,小忍者可以穿过各种障碍。它是忍者,不是上帝!所以,我们要想办法让地图里的障碍物产生碰撞(不可穿越)。有很多办法可以解决这个问题(包括使用对象层objects layers),但是我准备告诉你种新技术,我认为这种技术更有效,同时也是作为学习课程的好素材。使用meta layer和层属性。废话少说,我们开始吧。
&&&&&&& 用Tiled Map Editor打开之前创建的地图,点击Layer菜单的Add Tile
Layer取名Meta。我们会在这一层上放置一些假的Tile指示特殊的tile元件。点击Map菜单的New
Tileset,选择meta_tile.png图片。将Margin和Spacing设置为1。
你会在Tilesets窗口看到meta_tiles的标签。&&&&&&& &&&&&&& 这些tiles元件其实没什么特别的,只是带有透明特性的红色和绿色方块。我们拟定红色表示“可碰撞”的(绿色的后面会用到)。选中Meta层,选择印章(stamp)工具,选择红色tile元件。把它绘制到忍者不能穿越的地方。绘制好之后,看起来应该是这样的:&&&&&&& &&&&&& 接下来,我们要给这些Tile元件设置一些标记属性,这样在代码里我们可以确定哪些tile元件是不可穿越的。在Tilesets窗口里右键点击红色tile元件。添加一个新的属性Collidable”,设置值为true。&&&&& &&&&& 保存地图,回到xcode。修改HelloWorldScene.h文件。
//&Inside&the&HelloWorld&class&declarationCCTMXLayer&*_&//&After&the&class&declaration@property&(nonatomic,&retain)&CCTMXLayer&*[\cc]修改HelloWorldScene.m文件[cc&lang="objc"]//&Right&after&the&implementation&section@synthesize&meta&=&_&//&In&deallocself.meta&=&&//&In&init,&right&after&loading&backgroundself.meta&=&[_tileMap&layerNamed:@"Meta"];_meta.visible&=&NO;&//&Add&new&method-&(CGPoint)tileCoordForPosition:(CGPoint)position&{&&&&int&x&=&position.x&/&_tileMap.tileSize.&&&&int&y&=&((_tileMap.mapSize.height&*&_tileMap.tileSize.height)&-&position.y)&/&_tileMap.tileSize.&&&&return&ccp(x,&y);}
&&&&&&& 简单的对上面的代码做一些解释。我们定义了一个CCTMXLayer对象meta作为类成员。注意,我们将这个层设置为不可见,因为它只是用来处理碰撞的。&&&&&&&
接下来我们编写了一个tileCoordForPosition方法,用来将x,y坐标转换为地图网格坐标。地图左上角为(0,0)右下角为(49,49)。
上面带有坐标显示的截图来自java版本的编辑器。顺便说一声,我觉得在Qt版本里这个功能可能不再会被移植了。&&&&&&& 不管怎么样,用地图网格坐标要比用x,y坐标方便。得到x坐标比较方便,但是y坐标有点麻烦,因为在cocos2d里,是以左下作为原点的。也就是说,y坐标的向量与地图网格坐标是相反的。&&&&&&&
接下来,我们要修改一下setPlayerPosition方法。
CGPoint&tileCoord&=&[self&tileCoordForPosition:position];int&tileGid&=&[_meta&tileGIDAt:tileCoord];if&(tileGid)&{&&&&NSDictionary&*properties&=&[_tileMap&propertiesForGID:tileGid];&&&&if&(properties)&{&&&&&&&&NSString&*collision&=&[properties&valueForKey:@"Collidable"];&&&&&&&&if&(collision&&&&[collision&compare:@"True"]&==&NSOrderedSame)&{&&&&&&&&&&&&return;&&&&&&&&}&&&&}}_player.position&=&
&&&&&&& 这里,我们将主角的坐标系从x,y坐标(左下原点)系转换为tile坐标系(左上原点)。接下来,我们使用meta layer里的tileGIDAt函数获取tile坐标系里的GID。噢?什么是GID? GID应该是“全局唯一标识”(我认为).但是在这个例子里,把它作为tile层的id更贴切。&&&&&&&
我们使用GID来查找tile层的属性,返回值是一个包含属性列表的dictionary。我们检查“Collidable”属性是否设置为ture。如果是,则说明不可以穿越。很好,编译运行工程,你再也不能走入你在tile里设置为红色的区域了。&&&&&&&&
动态改变Tiled Maps
现在,你的小忍者可以在地图上漫游了,不过,整个游戏还是略显沉闷。&&&&&&&
假设我们的小忍者非常饿,那么我们设置一些食物,让小忍者可以找到并吃掉它们。
&&&&&&& 为了实现这个想法,我们要创建一个前端层,承载所有用于触碰(吃掉)的物体。这样,我们可以在忍者吃掉它们的同时,方便的从层上删除它。并且背景层不受任何影响。&&&&&&
打开Tiled Map Editor,Layer菜单的Add Tile Layer。命名新层为Foreground。选中这个层,添加一些可触碰的物件。我比较喜欢用西瓜。&&&&&& &&&&& 接下来,要让西瓜变为可触碰的。这次我们用绿色方块来标记。记得要在meta_tiles里做这件事。&&&&&& &&&&& 同样的,给绿色方块添加属性“Collectable”设置值为 “True”.&&&&&
保存地图,回到xcode。修改代码:
//in&HelloWorldScene.h://&Inside&the&HelloWorld&class&declarationCCTMXLayer&*_&//&After&the&class&declaration@property&(nonatomic,&retain)&CCTMXLayer&*
//in&HelloWorldScene.m//&Right&after&the&implementation&section@synthesize&foreground&=&_&//&In&deallocself.foreground&=&&//&In&init,&right&after&loading&backgroundself.foreground&=&[_tileMap&layerNamed:@"Foreground"];&//&Add&to&setPlayerPosition,&right&after&the&if&clause&with&the&return&in&itNSString&*collectable&=&[properties&valueForKey:@"Collectable"];if&(collectable&&&&[collectable&compare:@"True"]&==&NSOrderedSame)&{&&&&[_meta&removeTileAt:tileCoord];&&&&[_foreground&removeTileAt:tileCoord];}
&&&&&&& 这里有个基本的原则,要同时删除meta layer 和the foreground layer的匹配对象。编译运行,小忍者可以吃到美味的甜西瓜了。&&&&&&& 创建分数计数器&&&&&&&
小忍者现有吃有喝很开心,但是,我们想知道到底他吃了多少个西瓜。&&&&&&&
通常,我们在layer上看着顺眼的地方加个label来显示数量。但是,我们一直在移动层,这样会给我们带来很多的困扰。&&&&&&&
这是一个演示在一个场景里使用多个层的好例子。我们保留HelloWorld层来进行游戏,同时,增加一个HelloWorldHud层用来显示label(Hub = heads up display)。&&&&&&&
当然,这两个层需要一些方法来互相通讯。Hub层需要知道小忍者吃到了西瓜。有很多很多方法实现两个层之间的通信,但是我们使用尽量简单的方法来实现。我
们会让HelloWorld层管理一个HelloworldHub层的引用,在忍者迟到西瓜的时候,可以调用一个方法来通知Hub层。修改代码:
//&HelloWorldScene.h//&Before&HelloWorld&class&declaration@interface&HelloWorldHud&:&CCLayer{&&&&&&CCLabel&*}&-&(void)numCollectedChanged:(int)numC@end&//&Inside&HelloWorld&class&declarationint&_numCHelloWorldHud&*_&//&After&the&class&declaration@property&(nonatomic,&assign)&int&numC@property&(nonatomic,&retain)&HelloWorldHud&*
//&HelloWorldScene.m//&At&top&of&file@implementation&HelloWorldHud&-(id)&init{&&&&if&((self&=&[super&init]))&{&&&&&&&&CGSize&winSize&=&[[CCDirector&sharedDirector]&winSize];&&&&&&&&label&=&[CCLabel&labelWithString:@"0"&dimensions:CGSizeMake(50,&20)&&&&&&&&&&&&alignment:UITextAlignmentRight&fontName:@"Verdana-Bold"&&&&&&&&&&&&fontSize:18.0];&&&&&&&&label.color&=&ccc3(0,0,0);&&&&&&&&int&margin&=&10;&&&&&&&&label.position&=&ccp(winSize.width&-&(label.contentSize.width/2)&&&&&&&&&&&&-&margin,&label.contentSize.height/2&+&margin);&&&&&&&&[self&addChild:label];&&&&}&&&&return&}&-&(void)numCollectedChanged:(int)numCollected&{&&&&[label&setString:[NSString&stringWithFormat:@"%d",&numCollected]];}&@end&//&Right&after&the&HelloWorld&implementation&section@synthesize&numCollected&=&_numC@synthesize&hud&=&_&//&In&deallocself.hud&=&&//&Add&to&the&+(id)&scene&method,&right&before&the&returnHelloWorldHud&*hud&=&[HelloWorldHud&node];&&&&[scene&addChild:&hud];&layer.hud&=&&//&Add&inside&setPlayerPosition,&in&the&case&where&a&tile&is&collectableself.numCollected++;[_hud&numCollectedChanged:_numCollected];
&&&&&&& 没什么稀奇的,第二个层继承CCLayer,并且在右下角添加了一个label。我们将第二个层添加到场景(Scene)里并且把hub层的引用传递给HelloWorld层。然后修改HelloWorld层调用通知计数改变的方法。
编译运行,应该可以在右下角看到吃瓜计数器了。
音效和音乐&&&&&&&
众所周知,没有音效和音乐的游戏,称不上是个完整的游戏。接下来,我们做一些简单的修改,让我们的游戏带有音效和背景音。
//&HelloWorldScene.m//&At&top&of&file#import&"SimpleAudioEngine.h"&//&At&top&of&init&for&HelloWorld&layer[[SimpleAudioEngine&sharedEngine]&preloadEffect:@"pickup.caf"];[[SimpleAudioEngine&sharedEngine]&preloadEffect:@"hit.caf"];[[SimpleAudioEngine&sharedEngine]&preloadEffect:@"move.caf"];[[SimpleAudioEngine&sharedEngine]&playBackgroundMusic:@"TileMap.caf"];&//&In&case&for&collidable&tile[[SimpleAudioEngine&sharedEngine]&playEffect:@"hit.caf"];&//&In&case&of&collectable&tile[[SimpleAudioEngine&sharedEngine]&playEffect:@"pickup.caf"];&//&Right&before&setting&player&position[[SimpleAudioEngine&sharedEngine]&playEffect:@"move.caf"];
接下来做点什么呢?&&&&&&&
通过这篇教程,你应该对coco2d有了一些基本的了解。&&&&&&&
这里是按照整篇教程完成的工程文件,&&&&&&&
如果你感兴趣,我的好朋友Geek和Dad编写了一篇后续教程: 。这篇教程将告诉你,如何在游戏里添加敌人,武器,胜负场景等。
HPy4Si , [url=]oshykvrddhqi[/url], [link=]uqxsjxdqwiaw[/link],
随笔分类(81)
随笔档案(74)
微软高级反病毒研究员
很让人期待的博客...
我公司的网站,嘻嘻~
同学的博客
cntrump 的空间
我的英文博客
一个很棒的国外论坛
一个学弟办的论坛
积分与排名
阅读排行榜
评论排行榜2015年7月 Web 开发大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。tiled map editor(18)
&1&数据成员。
void mapScroll(CCPoint touchPoint); //地图滚动
void update(float dt); //更新
void itTiled(); //初始化地图
bool isExistTiled(CCPoint position);
//得到点击点所对应的砖块位置是否有砖块
void testCrashHeroWithCoin(); //英雄和金币碰撞检测
CC_SYNTHESIZE(CCTMXTiledMap*, _map, Map); //地图
CC_SYNTHESIZE(CCTMXLayer*, _crashLayer, CrashLayer); //碰撞检测层
CC_SYNTHESIZE(CCPoint, _viewPoint, ViewPoint);
//地图视图坐标点
CC_SYNTHESIZE(CCSprite*, _hero, Hero); //英雄主角
CC_SYNTHESIZE(CCArray*, _coinArray, CoinArray); //金币数据存储
bool HelloWorld::init()
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
CCSize size = CCDirector::sharedDirector()-&getWinSize();
_map = CCTMXTiledMap::create(&MyTiaoTest.tmx&);
addChild(_map);
_crashLayer = getMap()-&layerNamed(&crashLayer&);
_viewPoint = ccp(size.width/2, size.height/2);
_hero = CCSprite::create(&noodledie.png&);
_hero-&setAnchorPoint(ccp(0.5f, 0));
_hero-&setPosition(ccp(20, 360));
addChild(_hero);
_hero-&setScale(0.5f);
_coinArray = CCArray::create();
_coinArray-&retain();
itTiled();
scheduleUpdate();
void HelloWorld::mapScroll(CCPoint touchPoint) //地图的滚动。
CCSize winSize=CCDirector::sharedDirector()-&getWinSize();
int x=MAX(touchPoint.x, winSize.width/2);
int y=MAX(touchPoint.y, winSize.height/2);
x=MIN(x,(this-&getMap()-&getMapSize().width*this-&getMap()-&getTileSize().width)-winSize.width/2);
y=MIN(y,(this-&getMap()-&getMapSize().height*this-&getMap()-&getTileSize().height)-winSize.height/2);
CCPoint actualPosition=ccp(x,y);
CCPoint centerOfView=ccp(winSize.width/2,winSize.height/2);
CCPoint viewPoint=ccpSub(centerOfView,actualPosition);
//v1 - v2 也就是第一个减去第二个
this-&setPosition(viewPoint);
void HelloWorld::update(float dt)
_viewPoint = ccpAdd(_viewPoint, ccp(5, 0));
getHero()-&setPosition(ccpAdd(getHero()-&getPosition(), ccp(5, 0)));
mapScroll(_viewPoint);
if(getHero()-&getPositionY() & 0 && !isExistTiled(getHero()-&getPosition()))
getHero()-&setPosition(ccpSub(getHero()-&getPosition(), ccp(0, 5)));
else if(getHero()-&getPositionY() == 0)
getHero()-&setPosition(ccpAdd(getHero()-&getPosition(), ccp(0, 300)));
if(getHero()-&getPositionX() &= getMap()-&getContentSize().width - getHero()-&getContentSize().width/2)
unscheduleUpdate();
testCrashHeroWithCoin();
void HelloWorld::itTiled() //
CCTMXObjectGroup* group = getMap()-&objectGroupNamed(&coinLayer&);
//对象层,比如金币什么的。
CCArray* array = group-&getObjects();
CCObject* obj = NULL;
CCARRAY_FOREACH(array, obj)
CCDictionary* dic = dynamic_cast&CCDictionary*&(obj);
float x = dic-&valueForKey(&x&)-&floatValue();
float y = dic-&valueForKey(&y&)-&floatValue();
CCSprite* sp = CCSprite::create(&coin.png&);
sp-&setPosition(ccpAdd(ccp(x, y), ccp(getMap()-&getTileSize().width/2, getMap()-&getTileSize().height/2)));
addChild(sp);
getCoinArray()-&addObject(sp);
bool HelloWorld::isExistTiled(CCPoint position)
//一个普通的图层,里面可以用资源画上一些砖块
int x = position.x / getMap()-&getTileSize().
int y = (getMap()-&getContentSize().height - position.y) / getMap()-&getTileSize().
int flag =
getCrashLayer()-&tileGIDAt(CCPointMake(x, y));
return flag != 0 ? true :
void HelloWorld::testCrashHeroWithCoin()
/*第一种方法/
CCObject* obj = NULL;
CCARRAY_FOREACH(getCoinArray(), obj)
CCSprite* coin = dynamic_cast&CCSprite*&(obj);
if(coin-&boundingBox().intersectsRect(getHero()-&boundingBox()))
coin-&removeFromParent();
CCArray* coinDeleteArray = CCArray::create();
CCObject* obj = NULL;
CCARRAY_FOREACH(getCoinArray(), obj)
CCSprite* coin = dynamic_cast&CCSprite*&(obj);
if(coin-&boundingBox().intersectsRect(getHero()-&boundingBox()))
coinDeleteArray-&addObject(coin);
//*第二种方法/
CCARRAY_FOREACH(coinDeleteArray, obj)
CCSprite* coin = dynamic_cast&CCSprite*&(obj);
getCoinArray()-&removeObject(coin);
coin-&removeFromParent();
}总结:金币在对象层coinLayer,而碰撞检测是在一个普通的图层crashLayer。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:563326次
积分:15849
积分:15849
排名:第664名
原创:1060篇
评论:51条
(10)(9)(12)(58)(14)(20)(29)(6)(18)(16)(12)(42)(27)(48)(22)(27)(18)(22)(5)(10)(1)(7)(3)(7)(7)(51)(39)(13)(16)(2)(22)(21)(21)(27)(58)(81)(62)(23)(1)(12)(5)(17)(24)(32)(1)(3)(5)(2)(41)(4)(8)(9)(10)主题 : 【求助】添加tmx地图出现问题
级别: 新手上路
UID: 365686
可可豆: 47 CB
威望: 34 点
在线时间: 39(时)
发自: Web Page
【求助】添加tmx地图出现问题&&&
拜谢所有进来解决的大神。环境:cocoscreator 1.1.1ndk:32位r10ant:1.9.4本来想做cocos2d-js的那个入门跑酷教程,现在的进度是实现了背景的移动,接下来想添加地块,用Tiled工具写了一个tmx的地图。 tmx地图截图 把tmx文件直接从资源管理器拖拽到了层级管理器的背景中。 管理器截图 tmx地图中需要的ground资源也和tmx放到了一个文件夹里。而这个tmx文件的属性截图如下:
这时候在浏览器里运行,报了一个错误。TypeError: Cannot read property 'getAttribute' of undefined&&&&at _Class.cc.TMXMapInfo.cc.SAXParser.extend.parseXMLFile (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\bin\modular-cocos2d.js:21560:38)&&&&at _Class.cc.TMXMapInfo.cc.SAXParser.extend.parseXMLString (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\bin\modular-cocos2d.js:21773:21)&&&&at _Class.cc.TMXMapInfo.cc.SAXParser.extend.initWithXML (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\bin\modular-cocos2d.js:21469:21)&&&&at _Class.cc.TMXMapInfo.cc.SAXParser.extend.ctor (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\bin\modular-cocos2d.js:21242:18)&&&&at new _Class (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\cocos2d\core\platform\_CCClass.js:86:17)&&&&at _Class._ccsg.TMXTiledMap._ccsg.Node.extend.initWithXML (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\bin\modular-cocos2d.js:20821:23)&&&&at cc_TiledMap.cc.Class._applyFile (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\cocos2d\tilemap\CCTiledMap.js:706:30)&&&&at cc_TiledMap.cc.Class._initSgNode (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\cocos2d\tilemap\CCTiledMap.js:476:14)&&&&at cc_TiledMap.cc.Class.__preload (C:\Users\Administrator\AppData\Local\CocosCreator\app-1.1.1\resources\engine\cocos2d\core\components\CCRendererInSG.js:62:14)我顺着这个错误找下去,看到的是如下代码:Uncaught TypeError: Cannot read property 'getAttribute' of undefined&&&&&&&&&&&&&&&&&&&&&&&&&&modular-cocos2d.js:21559
才疏学浅,实在是不知道哪出问题了,静等回复,拜谢大神。
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版

我要回帖

更多关于 csgo跑酷地图 的文章

 

随机推荐