[PLUGIN] Polygon (update 2013-04-23)

Post your completed addons to share with the community

Post » Mon Feb 18, 2013 5:53 pm

Update:

Action:
  • Add Vertex
  • Move Vertex
  • Insert Vertex
  • -> A new combobox parameter has been added to choose between local and world-space for add/move/insert vertex
  • Set Origin
  • -> You can define a new origin for the object (this well automagically change the local position of the vertices and the position of the object so the origin is changed but the polygon itself doesn't bulge one bit)

Expression:
  • Right: X coordinate of the right edge of the unrotated bounding box
  • Bottom: Y coordinate of the bottom edge of the unrotated bounding box
  • Left: X coordinate of the left edge of the unrotated bounding box
  • Top: Y coordinate of the top edge of the unrotated bounding box
  • CenterX: X coordinate of the center off the bounding box
  • CenterY: Y coordinate of the center of the bounding box
  • BarycenterX: X coordinate of the barycenter (average of the vertices position)
  • BarycenterY: Y coordinate of the barycenter (average of the vertices position)


Here are some example of the uses of these new features.
The bouding box brackets are a 9-patch object placed using the bouding box expressions.
The blue cross is the bounding box center, the yellow cross is the origin and the gree cross is the barycenter.
https://dl.dropbox.com/u/23551572/C2-Games/Polygon%20Demo/index.htmlYann2013-02-18 18:04:31
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Feb 18, 2013 9:16 pm

Great!

Is it possible to use a tillable texture as the fill? Or could that be achieved using two layers and setting the poly layer to mask the textured layer?
B
24
S
11
G
5
Posts: 140
Reputation: 5,004

Post » Mon Feb 18, 2013 11:25 pm

@labithiotis
Yeah you can probably use masking, I still didn't work on texturing, don't know yet how and if I should handle that since there's easy work around like masking as you suggested.
And with containers it shouldn't be too hard to work with while allowing you to use either tiledbg or sprites.
I might try some stuff at some point just for testing but I don't promise anything (:
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Feb 20, 2013 12:37 am

Hey Yann

Is possible to convert from SVG lines to JSON and recreate the lines?
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,644

Post » Wed Feb 20, 2013 4:26 pm

@joannesalfa
Not without some effort on your side (:

If you're interested the JSON format of the polygon plugin is:[code]{
    'c2polygon':true,
    'vertexCount' : numberOfVertex,
    'vertices': [
                    [x0,y0],
                    [x1,y1],
                    [x2,y2],
                    ...
               ]
}[/code]

As long as you can create a JSON in such format, the plugin will gladly accept it and you'll be able to draw any polygon.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Feb 20, 2013 7:11 pm

@Yann - on your plugin, it 's cool!

do you think, that bezier curvers will be an option?

Aaand have a look at this awesome flash-engine-demo. Which ingredients do we need to replicate that into a plugin?

edit: well, it seems like i asked a similar question to labithiotis's. such an editor would be soooo awesome ;)oppenheimer2013-02-20 20:00:14
B
59
S
7
G
2
Posts: 93
Reputation: 4,228

Post » Thu Feb 21, 2013 3:45 am

[QUOTE=Yann] @joannesalfa
Not without some effort on your side (:

If you're interested the JSON format of the polygon plugin is:[code]{
    'c2polygon':true,
    'vertexCount' : numberOfVertex,
    'vertices': [
                    [x0,y0],
                    [x1,y1],
                    [x2,y2],
                    ...
               ]
}[/code]

As long as you can create a JSON in such format, the plugin will gladly accept it and you'll be able to draw any polygon.[/QUOTE]


I'm trying to recreate this with Polygon plugin

http://openclipart.org/people/zeimusu/zeimusu_Swash_ornament.svg


I doubt if is required to work with JSON or standard SVG path. Would you explain how do it or provide an example? If you can when you get change.

Thanks!
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,644

Post » Thu Feb 21, 2013 12:35 pm

@oppenheimer
Thanks, and I don't think you can make a plugin for that. I mean, it's a whole tool by itself. Plugins just add some simple functionnalities you can operate through action/condition/expression.
Now, even if this hypothetical plugin were to only read some data this tool output and draw the corresponding graphics. I think you would need some kind of mesh distorsion capabilities as well as some smart tiling effects. Like an enhanced 9-patch.
For distorsion, it might be achievable with WebGL (meaning, this wouldn't be compatible with devices that doesn't implement it).
The polygon plugin only uses the html5 Canvas 2D functionnalities. When WebGL is activated, it merely copy the canvas2D texture into the webGL context.


@joannesalfa
[quote=wikipedia]a polygon (pron.: /'p?l?g?n/) is a flat shape consisting of straight lines that are joined to form a closed chain or circuit[/quote]
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Feb 21, 2013 11:15 pm

[QUOTE=Yann]
@joannesalfa
[quote=wikipedia]a polygon (pron.: /'p?l?g?n/) is a flat shape consisting of straight lines that are joined to form a closed chain or circuit[/quote]
[/QUOTE]

I know what means polygon, sorry my mistake for saying "Path" which doesn't make sense.

However, it would have more than 50 vertex to create a complex shape.


Take a look:
http://www.w3schools.com/svg/svg_polygon.asp

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<polygon points="100,10 40,180 190,60 10,60 160,180"
style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
</svg>

Isn't possible to recreate this shape according to this code via JSON or something with your Polygon plugin?
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,644

Post » Fri Feb 22, 2013 1:06 am

@joannesalfa
My remark was more because you were showing me a curviline shape. I wanted to make sure you didn't want to make coffee with the plugin :D

Now, I won't write an svg to JSON converter.
But what I can tell you is that you just need to retrieve the value of the points attribute and recreate a json string by grouping the number by pairs

You can probably write something in C2 directly with 2 text boxes for input/output, and maybe using the xml plugin to retrieve the points attribute and then parsing it using some token function.

The example you posted should become something like:
[code]{
    'c2polygon':true,
    'vertexCount' : 5,
    'vertices': [
                    [100,10],
                    [40,180],
                    [190,60],
                    [10,60],
                    [160,180]
               ]
}[/code]



    
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 4 guests