3
votes

I got some problems with opengl and cocos2d. I suck with opengl i know. I was trying to find just a simple answer but no luck.

What I'm trying to do is to map a texture like this:

Example

... so i got points

CGPoint points[4];

points[0] = ccp(x1,y1);
points[1] = ccp(x2,y2);
points[2] = ccp(x3,y3);
points[3] = ccp(x4,y4);

Whats next :( ?

All I want to do is map that texture on that polygon. I will show it in "idiot" way :)

enter image description here

1
You may want to scour the CCSprite draw method to learn how Cocos2D renders the texture. A sprite is nothing but a texture mapped onto a 4-point polygon like yours. - LearnCocos2D

1 Answers

1
votes

Firstly I would design the texture with the bottom horizontal and then rotate the sprite at the end, as this makes it a whole lot easier.

I would load the texture into a UIImage. Then use CGContexts to remove the triangular portions in the top corners.

Then load that UIImage into a CCTexture2D which I would then create a sprite from. Then rotate the sprite, so that it is at the required orientation.

Alternatively, if you don't need the texture to be generated programmatically you could just remove the corners from the texture, using gimp, photoshop or pixelmator. Then just load that texture the same way you would load any other.