0

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);
};

啊啊啊

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

}

在此先感谢您的帮助。

4

1 回答 1

0

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

CCLog("[zfGameScene] Initialising with %f x %f...", winSize.width, winSize.height);
于 2012-10-22T16:14:16.497 回答