Is there any way to adjust the boundaries of the visible part of the sprite? To make it easier to understand: I have a texture, such as shown at figure 1. Then I break it into pieces and fill the resulting fragments using PRKit - http://www.cocos2d-x.org/boards/6/topics/8101?r=12361#message-12361 (wood texture on figure 2 and 3). But the resulting fragments have the transparent (green color on figure 2 and 3) and when creating a sprite from the fragments they have the size of the initial texture. Is there a way to get rid of this transparency and to adjust the size of the visible part (wood texture), openGL or cocos2d-x means?
Maybe it help - draw() method from PRKit:
void PRFilledPolygon::draw() {
//CCNode::draw();
glDisableClientState(GL_COLOR_ARRAY);
// we have a pointer to vertex points so enable client state
glBindTexture(GL_TEXTURE_2D, texture->getName());
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ONE_MINUS_SRC_ALPHA);
glVertexPointer(2, GL_FLOAT, 0, areaTrianglePoints);
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates);
glDrawArrays(GL_TRIANGLES, 0, areaTrianglePointCount);
//glColor4f(abs(rand()%255), abs(rand()%255), 0, 1.0f);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//Restore texture matrix and switch back to modelview matrix
glEnableClientState(GL_COLOR_ARRAY);
}
textur.jpg (37.6 KB)
Ok, i did this. First, i create texture from PRFilledPolygon (PRKit), use for that CCRenderTexture, after this i applied the resulting texture for new CCSprite and then i created a bounding box, using data from sites of PRKit and applied it to a sprite using setTextureRect ().
Hi Alex,
How to use PRFilledPolygon?
Could you share some sample code snippet about using PRFilledPolygon in cocos2d-x for me?
I had tried to use it,but it cann’t work correctly.
kundi jiang wrote:
Hi Alex,
How to use PRFilledPolygon?
Could you share some sample code snippet about using PRFilledPolygon in cocos2d-x for me?
I had tried to use it,but it cann’t work correctly.
Ok, take this:
std::vector polygonPoints;
polygonPoints.push_back(Vector2d(0, 0));
polygonPoints.push_back(Vector2d(10, 0));
polygonPoints.push_back(Vector2d(10, 10));
polygonPoints.push_back(Vector2d(0, 10));
CCTexture2D* pTexture = CCTextureCache::sharedTextureCache()->addImage("your_texture_image"); //must be power of 2 - 32x32, 64x64...512x512
PRFilledPolygon* aFilledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture(polygonPoints, pTexture);
CCRenderTexture* polygon = CCRenderTexture::renderTextureWithWidthAndHeight(pTexture->getPixelsWide(), pTexture->getPixelsHigh());
polygon->beginWithClear(1, 1, 1, 0);
aFilledPolygon->visit();
polygon->end();
CCSprite* myNewSprite = polygon->getSprite();
Hi Alex,Could help me about the problem I encountered, reference to url:
http://www.cocos2d-x.org/boards/6/topics/8101?r=14423#message-14423