0
votes

I came into a trouble with cocos2d-x, which I may not be able to solve alone, therefore I'm asking for your help. I wanted to create my own CCScene with CCLayer -as part of my cocos2d-x learning. Everything is working fine, except the size of the scene. CCDirector::sharedDirector()->getWinSize() report totally messed up resolution, like 0 x 108134400... and I don't know what I'm doing wrong.

Here is my class

.h
#pragma once
#include "cocos2d.h"

class zfGameScene : public cocos2d::CCLayer
{
public:
    static cocos2d::CCScene* scene();
    virtual bool init();
    CREATE_FUNC(zfGameScene);
};

Aaaaand

.cpp
#include "zfGameScene.h"
#include "cocos2d.h"

using namespace cocos2d;

CCScene* zfGameScene::scene(){
CCScene * scene = NULL;
    do 
    {
     scene = CCScene::create();
        CC_BREAK_IF(! scene);

        zfGameScene *layer = zfGameScene::create();
        CC_BREAK_IF(! layer);

        scene->addChild(layer);
    } while (0);

    return scene;
}

bool zfGameScene::init(){
    bool returnValue = false;
    while(!returnValue){
        CC_BREAK_IF(!CCLayer::init());

        // This one is for loading the scene :P
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCLog("[zfGameScene] Initialising with %d x %d...", winSize.width, winSize.height);

        CCSprite *background = CCSprite::spriteWithFile("background.png", CCRect(0, 0, 2048, 1536));
        this->setScale(1);
        this->setPosition(ccp(0, 0));
        this->addChild(background);

        returnValue = true;
    }

    return returnValue;

}

Thanks in advance for your help.

1

1 Answers

0
votes

Width and height are float. Just change your code like this:

CCLog("[zfGameScene] Initialising with %f x %f...", winSize.width, winSize.height);