3

我想要一个背景图像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);

有一些错误。谁能帮我!谢谢!

4

2 回答 2

2

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

于 2012-12-11T06:35:55.460 回答
1

它与 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);
于 2014-02-11T10:42:25.260 回答