Search code examples
iphoneobjective-cipadcocos2d-iphonetextures

How do I repeat sprite horizontally ?


I have got the code to repeat X- and Y- which is:

 bg = [CCSprite spriteWithFile:@"ipadbgpattern.png" rect:CGRectMake(0, 0, 3000, 3000)];
        bg.position = ccp(500,500);
        ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
        [bg.texture setTexParameters:&params];
        [self addChild:bg];

However, I do not know how to change the params in order for the background to repeat along the horizontal axis.


Solution

  • There's no parameter for that. Just make sure the CGRect spans the region where you want the texture to repeat, and the texture itself must be a power of two (ie 1024x1024).

    I'm guessing that maybe you're using a 1024x768 texture and then you'll see a gap between texture repeats.