import frames by alpha clipping

New releases and general discussions.

Post » Mon Oct 12, 2009 3:49 am

one feature that i think would be really useful is import frames of a spritesheet by alpha-clipping it. In my opinion this is much more powerful than the default grid clipping method. There's a 2d game engine(clanlib) that uses this method so i thought it would be great to have it on construct.
B
58
S
13
G
10
Posts: 632
Reputation: 12,515

Post » Mon Oct 12, 2009 5:21 pm

What is alpha clipping and how does it work?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,610

Post » Mon Oct 12, 2009 5:45 pm

B
11
S
3
G
8
Posts: 473
Reputation: 4,569

Post » Mon Oct 12, 2009 7:22 pm

Basically it's selecting certain parts of an image in a sprite sheet, based on whether or not that particular part of the image is surrounded by transparent, or the selected mask color's pixels.
I'd say the pitfalls for that kind of function should be obvious.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Mon Oct 12, 2009 8:38 pm

You mean the color mask?
B
11
S
3
G
8
Posts: 473
Reputation: 4,569

Post » Mon Oct 12, 2009 9:27 pm

No. More like magic pink.

[url:39chcl65]http://en.wikipedia.org/wiki/Chroma_key[/url:39chcl65]
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Tue Oct 13, 2009 1:02 am

yeah i know there's some restrictions when using this method. I've read the code that does this. it basically receives a png file , x, y and alpha limit by parameter. It then stores all pixel data in a matrix, reads it pixel by pixel beginning on position x,y , left from right , top to bottom, tests alpha value of pixel , if greater than alpha it marks it as opaque. In the end it returns all rects corresponding to the sprites in the spritesheet. How exactly the algorithm works i couldn't understand :?
one implication of this algorithm is that all sprites must be alligned by Y. example:



it would get the purple square first, not the blue one as it is expected, cause it is above the others
B
58
S
13
G
10
Posts: 632
Reputation: 12,515

Post » Sun Oct 18, 2009 10:14 pm

search and flood fill limited by alpha, then find bounds and clip.
Simple but slow. Could be sorted by bounding box center.
Should include a minimum bounding box size.

Issues could occur if sprites overlap each others bounding boxes, which is a rare case I'd say.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Oct 19, 2009 1:36 am

there's an alternative that i think uses a similar method but maybe would be more efficient, the technique used on [url:zncf0oci]http://bit.ly/49np5J[/url:zncf0oci] . You select the sprite in the spritesheet and it then shrinks the boundary to cover exactly the sprite frame. Then it exports the animation coordinates "map" as XML like <Frame1>rect(x,y,w,h) etc... Though you have yet to adjust the offset sometimes... I'd like to have the source code of this program : :|
B
58
S
13
G
10
Posts: 632
Reputation: 12,515

Post » Mon Oct 19, 2009 8:32 am

All of which can be accomplished with a decent image editor. So unless there's another function to crop said sheets at runtime, this is all pointless.... imho. Its just another proverbial easy button, best suited for something like Stencyl.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 3 guests