【问题标题】:cocos2d-x how to repeat a NPOT imagecocos2d-x 如何重复一个 NPOT 图像
【发布时间】:2014-02-11 18:42:25
【问题描述】:

我想要一个背景图片repeat-x,但不想改变图片的宽度和高度。

    CCSize s = CCDirector::sharedDirector()->getWinSize();
    CCSprite* sprite = CCSprite::create("sprite.png"); // the image size is 256 * 224, so the height is non power of 2.
    CCRect spriteRect = sprite->getTextureRect();
    spriteRect.size.width = s.width;
    pSkyBg->setTextureRect(skyRect);

    ccTexParams tp = { GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
    sprite->getTexture()->setTexParameters(&tp);

    sprite->setPosition((ccp(0, s.height)));
    sprite->setAnchorPoint(ccp(0, 1));
    addChild(sprite, 0);

有些不对劲。谁能帮我!谢谢!

【问题讨论】:

    标签: c++ cocos2d-x


    【解决方案1】:

    图片的高度和宽度必须是2的幂。显然224不是。

    【讨论】:

    • 我们不能使用 GL_WRAP 吗?
    【解决方案2】:

    它与 2 图像的幂完美配合。

    这是我的代码:

    CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("purty_wood.png");
    ccTexParams tp = { GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
    texture->setTexParameters(&tp);
    CCSprite *background = CCSprite::createWithTexture(texture, CCRectMake(0, 0, visibleSize.width, visibleSize.height));
    background->setPosition( ccp( visibleSize.width/2, visibleSize.height/2 ) );
    this->addChild(background, 1);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-21
      • 2014-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多