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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top