RotatingWheel
RotatingWheel

Reputation: 1041

Creating Tile Map and using in visual studio project

If I create a tile map by Tiled SW and include in my visual studio project then it crashes when I run the project with emulator. Some tmx files provided by cocos2d work fine in my example and some don't work. If I create a simple map by Tiled SW and include the tmx and png in my project it never work. Just wonder if my map is corrupted (created windows 8 with latest Tiled). Always get the following error. enter image description here

Any tips?

Update more info:

Call Stack:

libcocos2d.dll!cocos2d::CCTexture2D::hasPremultipliedAlpha() Line 173 C++ libcocos2d.dll!cocos2d::CCSpriteBatchNode::updateBlendFunc() Line 668 C++ libcocos2d.dll!cocos2d::CCSpriteBatchNode::initWithTexture(cocos2d::CCTexture2D * tex, unsigned int capacity) Line 90 C++ libcocos2d.dll!cocos2d::CCTMXLayer::initWithTilesetInfo(cocos2d::CCTMXTilesetInfo * tilesetInfo, cocos2d::CCTMXLayerInfo * layerInfo, cocos2d::CCTMXMapInfo * mapInfo) Line 65 C++ libcocos2d.dll!cocos2d::CCTMXLayer::create(cocos2d::CCTMXTilesetInfo * tilesetInfo, cocos2d::CCTMXLayerInfo * layerInfo, cocos2d::CCTMXMapInfo * mapInfo) Line 45 C++ libcocos2d.dll!cocos2d::CCTMXTiledMap::parseLayer(cocos2d::CCTMXLayerInfo * layerInfo, cocos2d::CCTMXMapInfo * mapInfo) Line 133 C++ libcocos2d.dll!cocos2d::CCTMXTiledMap::buildWithMapInfo(cocos2d::CCTMXMapInfo * mapInfo) Line 217 C++ libcocos2d.dll!cocos2d::CCTMXTiledMap::initWithTMXFile(const char * tmxFile) Line 75 C++ ShootingCar.exe!HelloWorld::init() Line 59 C++ ShootingCar.exe!HelloWorld::create() Line 28 C++ ShootingCar.exe!HelloWorld::scene() Line 26 C++ ShootingCar.exe!AppDelegate::applicationDidFinishLaunching() Line 52 C++ libcocos2d.dll!cocos2d::CCApplication::run() Line 71 C++ ShootingCar.exe!ShootingCar::[Windows::ApplicationModel::Core::IFrameworkView]::Run() Line 69 C++ [External Code] [Frames below may be incorrect and/or missing, no symbols loaded for AppModelCore.dll]

Calling Code:

_tileMap = new CCTMXTiledMap();
_tileMap->initWithTMXFile("untitled.tmx");
addChild(_tileMap); 

Crashes happens:

bool CCTexture2D::hasPremultipliedAlpha()
{
    return m_bHasPremultipliedAlpha;
}

Like I mentioned some tmx files work fine with this example (I just include and use the files). But for my tmx file never works, always crashes. I noticed some tmx file also crashes as my one (some in the cocos2d package)

Upvotes: 1

Views: 921

Answers (1)

RotatingWheel
RotatingWheel

Reputation: 1041

Uh! after some trial and error, I noticed the following reason was the root cause. If selected tile (png file) is in different directory than where tmx file is saved, Tiled SW add relative path in the XML file. The relative path goes to the resource and this causes the problem. In my case XML file contained the following: <image source="../TileGame/TileGame/Resources/TileGameResources/tmw_desert_spacing.png" width="265" height="199"/>

When drawing map then png file should be in the same folder or later XML file can be edited by removing the relative path.

Upvotes: 1

Related Questions