5

I was wondering how I should repeat a texture in Cocos2d 3. I have a background and I want to “tile” it across the screen. I have found this which is using ccTexParams with GL_REPEAT but those have been made private in version 3 of cocos.

I have found another solution which can be found here it creates a loop and positions a new child node based on the size of the texture and the size you want. But is that performant? Because when you have a 1px wide background texture and want to repeat that on a iPad retina, you have more than 2000 child nodes.

What is the best way to repeat a texture.

Community
  • 1
  • 1
Matthijn
  • 3,126
  • 9
  • 46
  • 69

2 Answers2

3

Well since there was no method for repeating without having a POT texture I made something of my own which takes care of it.

Might be useful for someone who has this same question. The code can be found here on Github.

Matthijn
  • 3,126
  • 9
  • 46
  • 69
  • It seems that this class creates new sprites inside render:, it looks like it can get really heavy. Also it won't work with Cocos2D v3 because sprite batch nodes are gone. – Jonny Sep 04 '14 at 04:46
0

CCTexture2D class has setTexParameters: method to set repeat mode. Also pay attention that the texture must have power-of-two width and height, otherwise repeating mode will be disabled.

brigadir
  • 6,874
  • 6
  • 46
  • 81
  • 1
    That is in version 2 and 1 if i'm correct. That method has been moved to CCTexture_Private.h (I could include that, but I was wondering why it has been made private). – Matthijn Dec 20 '13 at 15:42