2012-12-11 2 views
3

배경 이미지 repeat-x를 원하지만 이미지의 witdh 및 높이를 변경하고 싶지는 않습니다.cocos2d-x NPOT 이미지를 반복하는 방법

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

약간 잘못되었습니다. 누가 날 도울 수 있죠! 감사!

답변

2

이미지의 높이와 너비는 2의 거듭 제곱이어야합니다. 분명히 224는 아닙니다.

+0

우리가 GL_WRAP를 사용할 수 있습니까? – Pradeep

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); 
관련 문제