How to repeat sprite?

I’m using the following code:

auto sprite = Sprite::createWithTexture(t->getTexture(), Rect(0, 0, size.width, size.height));
Texture2D::TexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
sprite->getTexture()->setTexParameters(&params);

But I get warning that setTexParameters is deprecated. What’s the correct way to do this in cocos2d-x version 3.0?

if you look at the CCTexture2D.h header you’ll see:

void setTexParameters(const TexParams& texParams);

CC_DEPRECATED_ATTRIBUTE void setTexParameters(const TexParams* texParams) { return setTexParameters(*texParams); };

i.e. pass TexParams by reference not by pointer :smiley:

Can anyone post working sample code? I got SIG_ABORT at:

void Texture2D::setTexParameters(const TexParams &texParams)
{
CCASSERT((_pixelsWide == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) &&
    (_pixelsHigh == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE),
    "GL_CLAMP_TO_EDGE should be used in NPOT dimensions");
1 Like

Have you solved this trouble?

My working example:

auto border = Sprite::create("my.png");
border->getTexture()->setTexParameters({GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_REPEAT});
const auto& textureRect = border->getTextureRect();
		border->setTextureRect(
				{textureRect.origin.x, textureRect.origin.y, textureRect.size.width, MY_SUPER_BIG_SIZE});