タイトルのままです。背景をタイルのようにrepeatで敷き詰めたい時に。
(注) 背景にしたい画像は2の階乗のサイズである必要があります。
Scene.cpp
bool Scene::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);
:
: