1

I'm using Cocos2D. What is the most efficient way to tile an image when it's part of a texture atlas that's been generated using Texture Packer. I have an image that is 10 x 320 and I want to tile it to fill the screen.

I've used this code before for tiling images

bgHolder = [CCSprite spriteWithFile:@"bg.png" rect:CGRectMake(0, 0, 700, 300*155)];
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
[bgHolder.texture setTexParameters:&params];
[self addChild:bgHolder];

but I don't think I can use this approach when the image I want to tile isn't square and is only a small part of the over al texture.

Chaining a bunch of CCSprites seems pretty inefficient to me so I'm hoping there is a better way.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Tiddly
  • 1,620
  • 3
  • 21
  • 43

1 Answers1

1

Use one sprite per tile. That's the way to do it. You should use sprite batching to keep the number of draw calls to 1. Rendering 48 sprites is not much worse than rendering one 480x320 sprite when using sprite batching.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • I figured as much, was just hoping for some way to take advantage of GL_REPEAT or something along those lines. When moving and scaling the tiled sprites I get banding in between them. I guess I'll just have to play around with turning off the alising and truncating the spites positions and stuff like that. Cheers for answering. – Tiddly Aug 03 '12 at 11:20