RLH
RLH

Reputation: 15698

How can you repeat a background in cocos2d when HxW lengths are not a power of 2?

While trying to create a repeated tile overlay, I've found many questions (like this one) mentioning that repeated images in Cocos2d must have height and width dimensions that are powers of two.

This raises two questions. First, why is this a limitation? Second, and more importantly, how can I create a repeating, scrolling image that has dimensions that are not a power of two? What if I have a really wide background (say 4000 pixels) and I want it to repeat across the X axis. What should I do in that context? I can't believe the "correct" answer is to add an additional 96 pixels to the width, and increase the height of the image to 4096, as well. That's wasted bytes!

Upvotes: 0

Views: 283

Answers (1)

Ben Trengrove
Ben Trengrove

Reputation: 8729

This answer has excellent info on why the need for power of 2 textures.

Why do images for textures on the iPhone need to have power-of-two dimensions?

As for your second question, the texture does not have to be square, just both the width and height have to be a power of 2. So you could have an image that is 4096x128 repeating as your background. Keep in mind also that textures, no matter what the size, are always stored in memory in an uncompressed power of two size. So an image with width of 4000 and and an image with width of 4096 are actually using the same amount of memory.

Upvotes: 1

Related Questions