c++ - cocos2d-x 不理解图像/屏幕/比例,opengl windows 模拟器和真实设备之间的相对大小

标签 c++ iphone window cocos2d-x

经过长时间的开发,仅使用 visual studio 2012 在 windows opengl 模拟器上开发 每样东西看起来都应该在 480/320 屏幕尺寸上进行测试

CCSize screenSize = pEGLView->getFrameSize();
    CCSize designSize = CCSize(320, 480);

    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);

    if (screenSize.width > 640) {
        CCFileUtils::sharedFileUtils()->addSearchPath("ipadhd");
        pDirector->setContentScaleFactor(1280/designSize.width);
    } else if (screenSize.width > 320) {
        CCFileUtils::sharedFileUtils()->addSearchPath("ipad");
        pDirector->setContentScaleFactor(640/designSize.width);
    } else {
        CCFileUtils::sharedFileUtils()->addSearchPath("iphone");
        pDirector->setContentScaleFactor(320/designSize.width);
    } 

还有这个加载图片的函数

void GameLayer::loadImages()
{
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("sprites35.plist");
    m_gameBatchNode  = CCSpriteBatchNode::create("sprites.png",200);
    this->addChild(m_gameBatchNode,2,kSSheet);
    m_background  = CCSprite::create("gride300_300.png");
    m_background->setPosition(ccp(m_winSize.width/2,m_winSize.height/2));  
    this->addChild(m_background,kGrid);

}

当我第一次在我的设备 (iPhone 5) 中运行该应用程序时 所有尺寸的图像都变小了1/3并且位置都错了。
我的问题是如何使用开放式 GL 模拟器在 Windows 上进行开发,并且仍然可以在我的 iPhone 5 上看到所有内容
更新
我会提供更多信息 例如,我的背景图像大小为 297 x 297 像素 (1.00) 我这样放置:

m_background  = CCSprite::create("gride300_300.png");
m_background->setPosition(ccp(m_winSize.width/2,m_winSize.height/2));  
this->addChild(m_background,kGrid);

在模拟器中它看起来很棒。但是当我在 iPhone 中看到它时,它位于中间但非常小。不像在模拟器中

第二个例子:
我将大小为 35 x 35 像素 (1.00) 的圆形 gem 也放在中间 一个接一个,它们在模拟器中看起来都很棒,但当我在 iPhone 中看到它们时,它们又非常小
并对齐到屏幕的左下角,
这是放置 gem 的代码:

void Gem::placeInGride()
{
    CCSpriteBatchNode *spriteBatchNode = (CCSpriteBatchNode*) getGameController()->getGameLayer()->getChildByTag(kSSheet);
    int gemSelect =(rand() % totalGemsAvailable) + 1;

    GemType gemNum;
    gemNum =(GemType)gemSelect;
    setGemState(kGemNew);    
    char spritename[20];    
    sprintf(spritename,"gem%i_tranc.png",gemNum); 
    setImageName(spritename);
    setGemType(gemNum);    
    char spriteid[20];    
    sprintf(spriteid,"gem_%i_%i",getRowNum(),getColNum()); 
    std::string gemid(spriteid);
    setGemId(spriteid);
    mySprite = CCSprite::createWithSpriteFrameName(spritename);
    mySprite->setOpacity(255);
    spriteBatchNode->addChild(mySprite, 2);

    CCSize sSize = mySprite->getContentSize();
    setGemPosition(setPositionForGem(getRowNum(),getColNum(),sSize));

}

CCPoint Gem::setPositionForGem(int row,int col,const CCSize& gemSize)
{

    float leftPadding = 30 ; 
    float rightPadding = 37.5 ;
    float topPadding = 111.5;
    float buttonPadding = 90;
    float gemHight = gemSize.height;
    float gemWidth = gemSize.width;

    float x = (leftPadding+1) + ((gemWidth+2)*(col));
    float y = (topPadding+1)  + ((gemHight+2)*(row/*+1*/));
    return  ccp(x,y) ;

}

m 附上我的 iPhone 和 Windows 的屏幕截图

iphone_screen.PNG
windos_screen.jpg

最佳答案

我认为你的参数落后于

CCSize designSize = CCSize(320, 480);

应该是

CCSize designSize = CCSize(480,320);

你也试过使用

CCSize winSize = CCDirector::sharedDirector()->getWinSize();
验证设备使用的实际屏幕尺寸 然后像 this example that uses the iphone, ipad and ipadhd 那样从那里提供缩放图像.

关于c++ - cocos2d-x 不理解图像/屏幕/比例,opengl windows 模拟器和真实设备之间的相对大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18090864/

相关文章:

java - 在属性文件中写入属性而不破坏文件中的窗口路径

c++ - 创建解释性语言的过程是什么?

c++ - 获取使用 std::chrono 花费的平均时间

wpf - 使用 TPL 时避免窗口 (WPF) 卡住

iphone - 如何覆盖 iPhone 应用程序的图标?

iphone - Cocos2d-iPhone:dealloc后调用 "update"

javafx - 如何在JavaFX 8中使鼠标透明化?

c++ - 如何在另一个结构中初始化结构数组?

c++ - 使用 C++ 设置容器时出错

objective-c - UITableViewCell accessoryType位置随单元格高度变化