Alex Maximov Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 17
Added by Alex Maximov over 1 year ago

Hi Guys,

How about to implement/include some another new features (additionaly to mentioned in http://www.cocos2d-x.org/boards/6/topics/5775)?
1. Filledpolygon - I think would be usefull (e.g. for rendering some polygon landscape areas filled with a texture) addon for game developer. I used it in my game.
There is cocos2d (iPhone) project at:
https://github.com/asinesio/cocos2d-PRKit
I've ported it to cocos2dx, may attach my files if necessary.
2. Would be useful to have wrapped text node (that will wrap text to specified width) - to render descriptions, stories, etc. for game. Unfortunatelly have no code for that.
3. Would be useful to have Clip node - might be used for scroll boxes, wrapped text, etc. Also have no code for this.
4. Woudl be useful to have FileExists functionality. E.g. if some "game objects" have additional textures (with definite naming convention) and some don't and we need to create these additional textures if files exists and not create otherwise - I used this approach in my game (had to use native marmalade API). I know e.g. CCTextureCache::addImage will return NULL texture if file doesn't exist but why make redundant operations if file simply doesn't exist?
5. How about to include some TTF to FNT converting tool to cocos? TTF is already implemented for all platforms but it still performs slower than BMFont (?). I used hiero.jnlp - java tool, since TTF was not implemented in 0.9.x.

Thanks,
Alex

Damiano Mazzella RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 8
Added by Damiano Mazzella about 1 year ago

Hi alex,
can you share your PRKit code?

Damiano Mazzella RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 8
Added by Damiano Mazzella about 1 year ago

Hello everyone,
I've ported Additions Filledpolygon from cocos2d-iphone (project at: https://github.com/asinesio/cocos2d-PRKit) to cocos2d-x.

I hope can be useful.
D.

PRKit.zip (13.8 kB)

Herman Jakobi RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 112
Added by Herman Jakobi 11 months ago

I made a Cocos2d-X 2.0 port of your PRKit code

Damiano Mazzella RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 8
Added by Damiano Mazzella 11 months ago

Thanks, you've anticipated my post

;)

tony come RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 54
Added by tony come 11 months ago

awesome, this is what I want !! great work

Alex Zhd RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 70
Location Ukraine
Added by Alex Zhd 11 months ago

Damiano Mazzella wrote:

Hello everyone,
I've ported Additions Filledpolygon from cocos2d-iphone (project at: https://github.com/asinesio/cocos2d-PRKit) to cocos2d-x.

I hope can be useful.
D.

Yes, it is a very useful thing, i use it in my project! Good job. But i have one question there - http://www.cocos2d-x.org/boards/6/topics/12325
Maybe you know answer?

Chen Tony RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 1
Added by Chen Tony 11 months ago

It's very useful. but I can not download it.

kundi jiang RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 15
Added by kundi jiang 9 months ago

Herman Jakobi wrote:

I made a Cocos2d-X 2.0 port of your PRKit code

I used your cocos2d-x 2.0 PRKit code, But it cann't draw the PRFilledPolygon on the layer, following is my test code and I also attach the image file watermelon.png:

Vector2dVector vc;
vc.push_back(Vector2d(5,15));
vc.push_back(Vector2d(6,13));
vc.push_back(Vector2d(32,5));
vc.push_back(Vector2d(48,7));
vc.push_back(Vector2d(6,14));
vc.push_back(Vector2d(34,59));
vc.push_back(Vector2d(28,59));
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("watermelon.png");
PRFilledPolygon *filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture(vc,texture);
filledPolygon->setPosition(0,320);
this->addChild(filledPolygon,1);
Do you know what is wrong?

watermelon.png (4.7 kB)

Alex Zhd RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 70
Location Ukraine
Added by Alex Zhd 9 months ago

Try this:

filledPolygon->setAnchorPoint(ccp(0, 0));
filledPolygon->setPosition(ccp(0,0));
this->addChild(filledPolygon, 1);

kundi jiang RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 15
Added by kundi jiang 9 months ago

I have tried it,but the result all the same.

kundi jiang RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 15
Added by kundi jiang 9 months ago

Maybe my PRKIT code has some bug, I appriciate that you can share the PRKIT code on cocos2d-x you always use.
Thanks you.

Alex Zhd RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 70
Location Ukraine
Added by Alex Zhd 9 months ago

Do you have error when compile program?

kundi jiang RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 15
Added by kundi jiang 9 months ago

Alex Zhd wrote:

Do you have error when compile program?

No,It built smoothly;

Craig McMahon RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 6
Added by Craig McMahon 9 months ago

I'm also trying to get this to work. I'm running a cocos2d-iphone PRKit example alongside it with the same texture, and have confirmed that the polygon is correctly triangulated and all the texture coordinates are the same going into the draw function, but no texture appears on screen.

What would be a really great feature for CCDrawingPrimitives would be a ccDrawTexturedPoly(...) =)

Craig

Damiano Mazzella RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 8
Added by Damiano Mazzella 9 months ago

Hi all,
sorry but I've been away for the holidays :)

I attach the new version of PRKit for cocos2d-x 2.0.

I hope you find it useful,
D.

Bojan Drvarek RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 7
Added by Bojan Drvarek 8 months ago

Damiano Mazzella wrote:

Hi all,
sorry but I've been away for the holidays :)

I attach the new version of PRKit for cocos2d-x 2.0.

I hope you find it useful,
D.

The port is buggy on windows (and it crashes), BUT both on Windows and OS X iOS simulator, it doesnt triangulate as it should. I've attached an image to show what I mean.

Here's the code:

init method:
Vector2dVector vc;
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("slime_1.png");
filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);
this->addChild(filledPolygon, 4);

update method:
Vector2dVector vc;
for (vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it) {
Particle *p = *it;
vc.push_back(Vector2d(mul * p->x, mul * p->y));
}
filledPolygon->setPoints(vc);

Damiano Mazzella RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 8
Added by Damiano Mazzella 8 months ago

Bojan Drvarek wrote:

Damiano Mazzella wrote:

Hi all,
sorry but I've been away for the holidays :)

I attach the new version of PRKit for cocos2d-x 2.0.

I hope you find it useful,
D.

The port is buggy on windows (and it crashes), BUT both on Windows and OS X iOS simulator, it doesnt triangulate as it should. I've attached an image to show what I mean.

Here's the code:

init method:
Vector2dVector vc;
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("slime_1.png");
filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);
this->addChild(filledPolygon, 4);

update method:
Vector2dVector vc;
for (vector<Particle*>::const_iterator it = particles.begin(); it != particles.end(); ++it) {
Particle *p = *it;
vc.push_back(Vector2d(mul * p->x, mul * p->y));
}
filledPolygon->setPoints(vc);

Hi,
is you image NPOT?
Can you post slime_1.png used for test?

Ciao,
D.

Craig McMahon RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 6
Added by Craig McMahon 8 months ago

Damiano Mazzella wrote:

Hi all,
sorry but I've been away for the holidays :)

I attach the new version of PRKit for cocos2d-x 2.0.

I hope you find it useful,
D.

I've been testing it for a while and it seems to work great - thank you!

Bojan Drvarek RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 7
Added by Bojan Drvarek 8 months ago

Damiano Mazzella wrote:

Hi,
is you image NPOT?
Can you post slime_1.png used for test?

Ciao,
D.

Image is POT, I'm sending it as attachment. Does the point list need to be inputted in specific order or does the triangulator sort them out in format compatible with OpenGL?

slime_1.png (212.8 kB)

artur a RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 1
Added by artur a 8 months ago

Very good work Damiano Mazzella, after pulling a lot of hair trying to make another port work - I downloaded your port and it worked great! Thanks

Leonardo Gomez RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 3
Location Argentina
Added by Leonardo Gomez 6 months ago

Damiano Mazzella wrote:

Hi all,
sorry but I've been away for the holidays :)

I attach the new version of PRKit for cocos2d-x 2.0.

I hope you find it useful,
D.

Hi all! Im newbie in OpenGL and I find this port very usefull. Ive been use it for about a week, doing some tests whithout problems. But when I use this code in a more complicated project, it throws some random bugs. This minors bug where solved when I initialize these variables in class PRFilledPolygon class:

int areaTrianglePointCount;
CCTexture2D texture;
CCPoint *areaTrianglePoints;
CCPoint *textureCoordinates;
PRRatcliffTriangulator
triangulator;

To solve it I made a constructor directly in PRFilledPolygon.h:

PRFilledPolygon() {
areaTrianglePointCount = 0;
texture = NULL;
areaTrianglePoints = NULL;
textureCoordinates = NULL;
triangulator = NULL;
}

You can initialize the variables wherever you want.

Thanks again!
Leonardo...

qiujie tian RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 12
Added by qiujie tian 4 months ago

Hello,sir! i write my code like this:
@

texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png");

void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) {
//CCPoint test = pTouch->getLocationInView();
CCPoint test = pTouch->getLocation();
//points.push_back(new p2t::Point(test.x, test.y));
vc.push_back(Vector2d(test.x, test.y));
CCLog("--x=%f, --y=%f", test.x, test.y);
}

PRFilledPolygon *temp = PRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);

@

but the program will crash at
@void PRFilledPolygon::setTexture(CCTexture2D* texture2D) {

CCAssert(texture2D, @"NO TEXTURE SET");
CC_SAFE_RELEASE(texture);//crash at this line
texture = texture2D;
CC_SAFE_RETAIN(texture);
ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT };
texture->setTexParameters(&texParams);
updateBlendFunc();
calculateTextureCoordinates();

}
@

I don't know why. can you help me ? i use cocos2d-x 2.0.4 Thank you

Leonardo Gomez RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 3
Location Argentina
Added by Leonardo Gomez 4 months ago

qiujie tian wrote:

Hello,sir! i write my code like this:
@

texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png");

void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) {
//CCPoint test = pTouch->getLocationInView();
CCPoint test = pTouch->getLocation();
//points.push_back(new p2t::Point(test.x, test.y));
vc.push_back(Vector2d(test.x, test.y));
CCLog("--x=%f, --y=%f", test.x, test.y);
}

PRFilledPolygon *temp = PRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);

@

but the program will crash at
@void PRFilledPolygon::setTexture(CCTexture2D* texture2D) {

CCAssert(texture2D, @"NO TEXTURE SET");
CC_SAFE_RELEASE(texture);//crash at this line
texture = texture2D;
CC_SAFE_RETAIN(texture);
ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT };
texture->setTexParameters(&texParams);

updateBlendFunc();
calculateTextureCoordinates();

}
@

I don't know why. can you help me ? i use cocos2d-x 2.0.4 Thank you

I think this error its beacuse the texture, you load in the cache, was released by cocos2dx in some moment before want to use it in PRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);. Cocos2dx release it, but you still have a pointer to that texture, the when PRFilledPolygon wants to release some thing already released, it crash.

A possible solution, if it was the case, should be putting CC_SAFE_RETAIN(texture); after the line texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png"); to prevent that cocos2dx dispose. And maybe, somewere, do a CC_SAFE_RELEASE(texture); after you use it or in the destructor of that class. Hope this work.

qiujie tian RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 12
Added by qiujie tian 4 months ago

Leonardo Gomez wrote:

qiujie tian wrote:

Hello,sir! i write my code like this:
@

texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png");

void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) {
//CCPoint test = pTouch->getLocationInView();
CCPoint test = pTouch->getLocation();
//points.push_back(new p2t::Point(test.x, test.y));
vc.push_back(Vector2d(test.x, test.y));
CCLog("--x=%f, --y=%f", test.x, test.y);
}

PRFilledPolygon *temp = PRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);

@

but the program will crash at
@void PRFilledPolygon::setTexture(CCTexture2D* texture2D) {

CCAssert(texture2D, @"NO TEXTURE SET");
CC_SAFE_RELEASE(texture);//crash at this line
texture = texture2D;
CC_SAFE_RETAIN(texture);
ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT };
texture->setTexParameters(&texParams);

updateBlendFunc();
calculateTextureCoordinates();

}
@

I don't know why. can you help me ? i use cocos2d-x 2.0.4 Thank you

I think this error its beacuse the texture, you load in the cache, was released by cocos2dx in some moment before want to use it in PRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);. Cocos2dx release it, but you still have a pointer to that texture, the when PRFilledPolygon wants to release some thing already released, it crash.

A possible solution, if it was the case, should be putting CC_SAFE_RETAIN(texture); after the line texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png"); to prevent that cocos2dx dispose. And maybe, somewere, do a CC_SAFE_RELEASE(texture); after you use it or in the destructor of that class. Hope this work.

Hello,sir. thank you for your reply. but it also crash at that line , i write this:
texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png");
CC_SAFE_RETAIN(texture);

please help me

qiujie tian RE: Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.
Posts 12
Added by qiujie tian 4 months ago

can you give me your code .......you said you use it smoothly. thank you


1 2 Next » (1-25/30)