首先重复贴图的图片的宽和高必须是2的n次幂,这里选择一张128*128的小图片来做例子

Cocos2d-x一张小背景重复贴图充满整个屏幕_cocos2d-x

代码如下:

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto bg=Sprite::create("BackgroundTile.png",Rect(0,0,visibleSize.width,visibleSize.height));
	Texture2D::TexParams tp={GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
	bg->getTexture()->setTexParameters(tp);
	bg->setPosition(visibleSize.width/2,visibleSize.height/2);

	this->addChild(bg,0);

运行得到如下效果:

    Cocos2d-x一张小背景重复贴图充满整个屏幕_ 背景贴图_02