Created
July 4, 2014 11:10
-
-
Save rdtr/456f2b098e85305fa13d to your computer and use it in GitHub Desktop.
cocos2d-x: how to repeat the background image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool GameScene::init() | |
{ | |
////////////////////////////// | |
if ( !Layer::init() ) | |
{ | |
return false; | |
} | |
Size visibleSize = Director::getInstance()->getVisibleSize(); | |
Vec2 origin = Director::getInstance()->getVisibleOrigin(); | |
// Set an image to a texture, set the param "repeat" | |
Texture2D *bgTexture = Director::getInstance()->getTextureCache()->addImage("bg.jpg"); | |
const Texture2D::TexParams tp = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT}; | |
// use the texture as Sprite | |
Sprite *background = Sprite::createWithTexture(bgTexture, Rect(0, 0, visibleSize.width, visibleSize.height)); | |
background->getTexture()->setTexParameters(&tp); | |
background->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); | |
this->addChild(background, 1); | |
: | |
: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setTexParameters
is deprecated