How to repeat the sprite horizontally?

I have code to repeat X- and Y- which:

 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 settings so that the background repeats along the horizontal axis.

+5
source share
2 answers

There are no options for this. Just make sure that CGRect covers the area in which you want the texture to repeat, and the texture itself should be equal to two (i.e. 1024x1024).

I assume that you are probably using a texture of 1024x768, and then you will see a gap between the repeats of the textures.

+3
source

This cannot be achieved at the GL level, since GL_REPEAT expects textures with power parameters of two.

TiledSprite , :

https://gist.github.com/Nolithius/6694990

:

http://www.nolithius.com/game-development/cocos2d-iphone-repeating-sprite

+1

All Articles