Forum > C++ > Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.

Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.

By almax Posted 2012-02-09 14:50 Comments 30
almax
  • Posts: 17

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

dmazzella
  • Posts: 8

#1 RE: 2012-03-17 16:40

Hi alex,
can you share your PRKit code?

dmazzella
  • Posts: 8

#2 RE: 2012-03-18 22:11

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)

festival
  • Posts: 119
  • Location: Germany

#3 RE: 2012-06-22 20:49

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

It works, ship it!

dmazzella
  • Posts: 8

#4 RE: 2012-06-22 21:29

Thanks, you’ve anticipated my post

;)

tonycome
  • Posts: 54

#5 RE: 2012-06-23 03:09

awesome, this is what I want []() great work

CrazyD0G
  • Posts: 78
  • Location: Ukraine

#6 RE: 2012-06-23 10:55

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?

mfc2000
  • Posts: 1

#7 RE: 2012-07-05 09:13

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

jiangjkd
  • Posts: 15

#8 RE: 2012-08-16 06:14

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;
PRFilledPolygon *filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture;
filledPolygon~~>setPosition(0,320);
this->addChild(filledPolygon,1);
Do you know what is wrong?

watermelon.png (4.7 kB)

CrazyD0G
  • Posts: 78
  • Location: Ukraine

#9 RE: 2012-08-17 08:14

Try this:

filledPolygon->setAnchorPoint(ccp(0, 0));
filledPolygon->setPosition(ccp(0,0));
this->addChild(filledPolygon, 1);
jiangjkd
  • Posts: 15

#10 RE: 2012-08-17 10:20

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

jiangjkd
  • Posts: 15

#11 RE: 2012-08-17 10:26

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

CrazyD0G
  • Posts: 78
  • Location: Ukraine

#12 RE: 2012-08-17 10:28

Do you have error when compile program?

jiangjkd
  • Posts: 15

#13 RE: 2012-08-17 13:31

Alex Zhd wrote:

Do you have error when compile program?

No,It built smoothly;

craigTheBrit
  • Posts: 6

#14 RE: 2012-08-26 04:32

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

dmazzella
  • Posts: 8

#15 RE: 2012-09-02 17:06

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.

duke4e
  • Posts: 7

#16 RE: 2012-09-24 11:44

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;
filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture;
this~~>addChild;
@
update method:@
Vector2dVector vc;
for ; it != particles.end; ++it) {
Particle
p = *it;
vc.push_back(Vector2d(mul * p~~>x, mul * p~~>y));
}
filledPolygon->setPoints(vc);
@

dmazzella
  • Posts: 8

#17 RE: 2012-09-24 17:32

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;
filledPolygon = PRFilledPolygon::filledPolygonWithPointsAndTexture;
this~~>addChild;
@
>
update method:@
Vector2dVector vc;
for ; 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.

craigTheBrit
  • Posts: 6

#18 RE: 2012-09-25 01:23

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!

duke4e
  • Posts: 7

#19 RE: 2012-09-25 09:41

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)

arturhood
  • Posts: 1

#20 RE: 2012-09-26 05:49

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

template
  • Posts: 3
  • Location: Argentina

#21 RE: 2012-11-17 14:55

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…

qq200600
  • Posts: 12

#22 RE: 2013-01-18 16:45

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

texture = CCTextureCache::sharedTextureCache()~~>addImage;
void HelloWorld::ccTouchMoved
{
//CCPoint test = pTouch~~>getLocationInView();
CCPoint test = pTouch~~>getLocation;
//points.push_back);
vc.push_back);
CCLog;
}
PRFilledPolygon *temp = PRFilledPolygon::filledPolygonWithPointsAndTexture;
@
but the program will crash at
`void PRFilledPolygon::setTexture(CCTexture2D* texture2D) {

CCAssert(texture2D, `“NO TEXTURE SET”);

CC_SAFE_RELEASE;//crash at this line
texture = texture2D;
CC_SAFE_RETAIN;
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

template
  • Posts: 3
  • Location: Argentina

#23 RE: 2013-01-18 19:22

qiujie tian wrote:

Hello,sir! i write my code like this:
@
>
texture = CCTextureCache::sharedTextureCache()~~>addImage;
>
void HelloWorld::ccTouchMoved
{
//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;
>
@
>
but the program will crash at
`void PRFilledPolygon::setTexture(CCTexture2D* texture2D) {

CCAssert(texture2D, `“NO TEXTURE SET”);

CC_SAFE_RELEASE;//crash at this line
texture = texture2D;
CC_SAFE_RETAIN;
ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT };
texture->setTexParameters;
>
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; to prevent that cocos2dx dispose. And maybe, somewere, do a CC_SAFE_RELEASE; after you use it or in the destructor of that class. Hope this work.

qq200600
  • Posts: 12

#24 RE: 2013-01-19 03:52

Leonardo Gomez wrote:

qiujie tian wrote:
> Hello,sir! i write my code like this:
> @
>
> texture = CCTextureCache::sharedTextureCache()~~>addImage;
>
> void HelloWorld::ccTouchMoved
> {
> //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;
>
> @
>
> but the program will crash at
> `void PRFilledPolygon::setTexture(CCTexture2D* texture2D) {

CCAssert(texture2D, `“NO TEXTURE SET”);

> CC_SAFE_RELEASE;//crash at this line
> texture = texture2D;
> CC_SAFE_RETAIN;
> ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT };
> texture->setTexParameters;
>
> 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; to prevent that cocos2dx dispose. And maybe, somewere, do a CC_SAFE_RELEASE; 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

qq200600
  • Posts: 12

#25 RE: 2013-01-19 03:54

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

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps