Question

I am using the latest cocos-2dx-3.0 following this tutorial.

http://www.raywenderlich.com/39113/cocos2d-x-tile-map-tutorial-part-1

I made a really basic tmx file, it loads fine and I add it to the screen, but nothing is ever displayed, just a blank screen. Here is the code:

bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

    auto tileMap = cocos2d::TMXTiledMap::create("tileset.tmx");
    tileMap->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(tileMap, 0);

    //auto sprite = Sprite::create("HelloWorld.png");
    //sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    //this->addChild(sprite, 0);

    return true;
}

So stepping through everything seems to load fine, it finds the file and I see all it's properties, but when added to the layer nothing is displayed. To be sure everything else is wired up correctly, the 3 lines commented below it work perfectly and it loads and displays on the screen. Anybody have any idea why this may be happening?

Était-ce utile?

La solution

OK, so after hours of debugging I actually realized everything was actually working perfectly. The problem was my .tmx file, which had a big blank spot in the corner where I hadn't placed anything yet (just trying to get something loaded initially). However initially loading zooms into the bottom left corner, which was blank, making me think nothing had loaded.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top