简体   繁体   中英

CCTMXTileMap works on simulator but not on device

I have a TMX Tile Map which I use for the background of an app I am making which uses cocos2d. When I use the Simulator, everything runs perfectly. However, if I use the device, everything goes wrong. On launch, it starts out with the loading screen at a full screen, but quickly transitions to: 加载后的图片

And then a black screen. It then gives me the console output of:

1970-01-02 10:57:56.-721 TankMazeNEW[729:707] cocos2d: surface size: 960x640
1970-01-02 10:57:56.-709 TankMazeNEW[729:707] cocos2d: CCTexture2D: Using RGB565texture since image has no alpha
1970-01-02 10:57:57.-645 TankMazeNEW[729:707] -[CCFileUtils fullPathFromRelativePath:resolutionType:] : cocos2d: Warning: File not found: /Users/vivaanbahl/Desktop/Iphone Apps/TankMazeNEW/TankMazeNEW/tanks.png
1970-01-02 10:57:57.-642 TankMazeNEW[729:707] cocos2d: CCTexture2D. Can't create Texture. cgImage is nil
1970-01-02 10:57:57.-638 TankMazeNEW[729:707] cocos2d: Couldn't add image:/Users/vivaanbahl/Desktop/Iphone Apps/TankMazeNEW/TankMazeNEW/tanks.png in CCTextureCache
1970-01-02 10:57:57.-528 TankMazeNEW[729:707] cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from [3501] to [4669].
1970-01-02 10:57:57.-487 TankMazeNEW[729:707] cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from [4669] to [6226].
1970-01-02 10:57:57.-435 TankMazeNEW[729:707] cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from [6226] to [8302].
1970-01-02 10:57:57.-364 TankMazeNEW[729:707] cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from [8302] to [11070].

The image that it 'isn't finding' is the source image containing the images to the tile appearances, and it is inside the project folder, at the filepath specified above in the log. Can someone see what I'm doing wrong?

resizing TextureAtlas capacity from [8302] to [11070].

I wager your tilemap is simply too big. On the simulator it doesn't matter that much since the Simulator makes use of your Mac's memory, which is probably anywhere between 2 to 16 GB. The largest iPad can offer is 1 GB, and earlier devices only have between 128 to 512 MB.

Do a simple math test: multiply your tilemap width and height, then multiply it by the number of tile layers in your tilemap. That gives you the least amount of memory in Bytes the tilemap would use if each tile would only require 1 Byte.

Since that's not the case, multiply the figure by 50 Bytes, which comes closer to what a tile really consumes (it's definitely more than 32 bytes).

A 1000x1000 tilemap with two layers consumes nearly 100 megabytes.

Is tanks.png spelled correctly?

Open up the TMX file in Notepad and search for tanks.png to see if it might be misspelled or not in the correct path.

I had the same exact issue: What worked for me was adding the .png file of the tile set as well to the Xcode project. When it runs in the simulator Xcode knows how to find the .png file since it's in the same folder as the .TMX file. After adding the tile set .png to the Xcode project it worked fine on the device as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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