Skip to content

Instantly share code, notes, and snippets.

@rdtr
Created July 4, 2014 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdtr/456f2b098e85305fa13d to your computer and use it in GitHub Desktop.
Save rdtr/456f2b098e85305fa13d to your computer and use it in GitHub Desktop.
cocos2d-x: how to repeat the background image
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);
:
:
@dzpt
Copy link

dzpt commented Apr 26, 2017

setTexParameters is deprecated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment