Cocos2d-x - CCDirector :: sharedDirector() - > getWinSize()在Win32上返回完全错误的值

时间:2012-10-22 14:58:44

标签: c++ cocos2d-iphone cocos2d-x

我遇到了cocos2d-x的麻烦,我可能无法单独解决,因此我在寻求你的帮助。我想用CCLayer创建自己的CCScene - 这是我的cocos2d-x学习的一部分。一切都很好,除了场景的大小。 CCDirector :: sharedDirector() - > getWinSize()报告完全搞砸了分辨率,比如 0 x 108134400 ......我不知道我做错了什么。

这是我的班级

.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;

}

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

宽度和高度是浮动的。只需更改您的代码:

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