5

I have a shape and texture image.. (shape.png, texture.png)

I would like to paint a shape as texture.png pattern in cocos2d. (shape size is pretty bigger than texture image. so automatically fill texture pattern in entire shape.

I trying to know the way.

Can't find..

someone have a solution to solve this problem?

James Webster
  • 31,873
  • 11
  • 70
  • 114
S.J. Lim
  • 3,095
  • 3
  • 37
  • 55

1 Answers1

7
sprite = [[CCSprite alloc] initWithFile:@"texture.png"];

ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
[sprite.texture setTexParameters:&params];
[sprite setTextureRect: CGRectMake(0.0, 0.0, w, h)];

This code repeats a texture in both the x and the y (or s, t in texture terms). The only limitation is that your texture must be a power of two (ie. 64 * 128, 128 * 128, 1024 * 1024) etc.

James Webster
  • 31,873
  • 11
  • 70
  • 114