简体   繁体   English

如何在cocos2d中加载大尺寸CCTMXTiledMap?

[英]How to load big size CCTMXTiledMap in cocos2d?

I try to design a cocos2d game that with a big world. 我尝试设计一个拥有广阔世界的cocos2d游戏。 The wolrd tiled map is very big, maybe 20 ipad screen sizes. 世界平铺的地图非常大,可能有20个ipad屏幕尺寸。 I want to know how to load CCTMXTiledMap into screen? 我想知道如何将CCTMXTiledMap加载到屏幕中吗? If I directly add it to screen, will it use too much memory? 如果我直接将其添加到屏幕上,会占用太多内存吗? If so, is there a solution to solve this problem? 如果是这样,是否有解决此问题的解决方案?

The memory usage of the tilemap depends on the size of the tiles and how many of the tiles need to be converted to sprites, for example if you want to run animate them. tilemap的内存使用量取决于tile的大小以及需要将多少个tile转换为sprite,例如,如果要对其进行动画处理。

Assuming your tiles are 32x32 pixels in size. 假设您的图块尺寸为32x32像素。 20 times iPad dimensions means 20.480x15.360 points. iPad尺寸的20倍意味着20.480x15.360点。 Divided by 32 gives you a tile size of the map of 640x480 tiles, or 307.200 tiles total. 除以32可得到640x480瓦片地图的瓦片大小,或总计307.200瓦片。 Assuming that each tile uses 64 Bytes memory (in an older cocos2d version it was less than 64 bytes) your map ends up using almost 19 MB of memory. 假设每个图块使用64字节的内存(在较早的cocos2d版本中,它小于64字节),则您的地图最终将使用近19 MB的内存。 That's not even counting the textures. 那甚至不算纹理。

Now for every tile that you address via the CCSprite interface, for example by changing one of the sprite properties or running actions on it, cocos2d will convert that tile to a regular CCSprite. 现在,对于您通过CCSprite接口处理的每个磁贴,例如通过更改sprite属性之一或在其上运行操​​作,cocos2d都会将该磁贴转换为常规CCSprite。 Each CCSprite object uses around 420 Bytes last time I checked. 上次检查时,每个CCSprite对象使用大约420字节。 So if you were to change the color property of each tile thus converting all tiles to CCSprite objects, the tilemap would consume 123 MB of memory. 因此,如果要更改每个图块的color属性,从而将所有图块都转换为CCSprite对象,则图块映射将占用123 MB的内存。 Again, not including textures. 同样,不包括纹理。

You could try the Tilemap renderer in KoboldTouch . 您可以在KoboldTouch中尝试TileMap渲染器 It can handle very large tilemaps (millions of tiles, ie 4000x4000 tiles) and renders it at 60 fps. 它可以处理非常大的图块地图(数百万个图块,即4000x4000图块),并以60 fps的速度渲染。

If you try to load all the tiles at one, it will definitely occupy too much memory. 如果您尝试一次加载所有图块,则肯定会占用过多内存。

Have a look at this tutorial about CCTMXTilesMap . 看一下有关CCTMXTilesMap的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM