How works the color argument in nme.Graphics.drawTriangles ?

Hello ! I'm working with graphics.drawTriangles to build a basic paint app on my Android device and I saw that graphics.drawTriangles accepts more argument than the AS3 version such as 'colors' or 'blendmode'. The color argument looks very interesti…

Viewing 1 to 5 (5 Total)
How works the color argument in nme.Graphics.drawTriangles ?

tlecoz

tlecoz
Total Posts: 31
Joined: November 26, 2011

Hello !

I'm working with graphics.drawTriangles to build a basic paint app on my Android device and I saw that graphics.drawTriangles accepts more argument than the AS3 version such as 'colors' or 'blendmode'.

The color argument looks very interesting but I can't find the way to use it

I tryed to create an Array and push inside one hexadecimal-code (=> 0xff000) for each Vertex but it doesn't work ; I tryed to push inside one hexadecimal-code for each triangle but it doesn't work.

When I say 'it doesn't work', I mean nothing appear on the screen (if I remove the color argument, my drawPath works correctly).


...I really have no idea on how it could work smiling


Can someone help me please .


Thank you by advance !


PS : excuse me if my english is not very good, I'm from France (this is not an excuse I know ....)

Tags:
Posted on November 27, 2011 at 9:09 PM

singmajesty

singmajesty
Total Posts: 2141
Joined: August 25, 2011

Re: How works the color argument in nme.Graphics.drawTriangles ?

I just made a change to SVN, which changes a couple things with drawTriangles which may be of help.

The colors array should be a set of vertex colors. You can use the same color for each vertex, or use different colors to apply a gradient. Previously the format was ABGR, which I think was confusing. I've updated NME to expect colors in ARGB format.

It would also crash if you did not call beginFill before calling drawTriangles. Since you can specify your own vertex colors, I fixed it so you can move directly to drawTriangles.

If you are working from SVN, this code should work:

graphics.drawTriangles ([ 0.0, 10, 0, 100, 100, 50 ], [ 0, 1, 2 ], null, null, [ 0x80FFFF00, 0xFFFF0000, 0xFFFF0000 ]);

This draws a red triangle, with one corner yellow and semi-transparent. To achieve the same effect on the current release, you would have to use it like this:

graphics.beginFill (0, 0);
graphics.drawTriangles ([ 0.0, 10, 0, 100, 100, 50 ], [ 0, 1, 2 ], null, null, [ 0x8000FFFF, 0xFF0000FF, 0xFF0000FF ]);

Posted on November 28, 2011 at 1:44 PM

tlecoz

tlecoz
Total Posts: 31
Joined: November 26, 2011

Re: How works the color argument in nme.Graphics.drawTriangles ?

Nice ! Thank you !

So it's not possible to use colors with beginBitmapFill ?
It could be great to use it like a colorTransform (but it 's probably hard to build)

Posted on November 28, 2011 at 2:09 PM

singmajesty

singmajesty
Total Posts: 2141
Joined: August 25, 2011

Re: How works the color argument in nme.Graphics.drawTriangles ?

I believe it should work just fine with bitmaps. Yeah, just call beginBitmapFill first -- I was testing with only a solid color fill, so that's why I was handling that error case. I believe the vertex colors were specifically added for use with bitmaps originally

Posted on November 28, 2011 at 2:30 PM

tlecoz

tlecoz
Total Posts: 31
Joined: November 26, 2011

Re: How works the color argument in nme.Graphics.drawTriangles ?

Fantastic !!! Youpi !!!

I 'll test it right now ! smiling

Posted on November 28, 2011 at 3:20 PM