Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill texture in cocos2d?

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?

like image 900
S.J. Lim Avatar asked Sep 05 '11 07:09

S.J. Lim


1 Answers

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.

like image 62
James Webster Avatar answered Sep 30 '22 00:09

James Webster