View polygon shape + sprite at the same time

39 views
Skip to first unread message

Razeware LLC

unread,
Dec 18, 2010, 4:40:28 PM12/18/10
to Mekanimo
Hi there,

I'm trying to trace a polygon around a sprite in Mekanimo. Here's
what I tried so far:

1) Added a box body and attached a sprite to it
2) Used the polygon tool to trace the sprite
3) Deleted the box body, and attached the sprite to the polygon
4) The sprite does not match up exactly to the polygon, so I need to
set its offset.

Unfortunately, it looks like Mekanimo doesn't have any way to see the
body on top of the sprite, so you can easily set the correct offset to
make sure they match. The only way I could do this was by dragging
the sprite, at which point you can see the outline.

Is there an easier way to do this/workaround, or is this something
that could be added to a future version?

Thanks,

--Ray Wenderlich, Razeware LLC

Fahri

unread,
Dec 18, 2010, 7:45:12 PM12/18/10
to Mekanimo
Hi Ray,

Currently there is no setting to let you see both the shape and the
sprite simultaneously. I think I should add this feature. For now
there is a workaround. Create your polygon, then copy and paste this
polygon with 0, 0 offset. Finally assign a sprite to your first
polygon. After you are done modifying the polygon delete the other
one.

Regards

Ray Wenderlich

unread,
Dec 19, 2010, 2:26:34 PM12/19/10
to Mekanimo
Hi Fahri,

Thanks for the response.

I tried what you suggested and that is a good workaround for getting
the sprite and the polygon shape to match up by setting the sprite
offset.

However, after playing around with it a bit more I'm starting to
realize that still doesn't solve my problem. I need to find a way to
trace a sprite with a polygon shape, and to get the sprite to match
the polygon shape without having to modify the sprite offset. This is
because I want to export Box2D C++ code from Mekanimo, and set the
sprite's position to the body's position in code (so they have to
match up exactly).

There's a tool I've used in the past called Vertex Helper that let you
do this. It let you trace a sprite and would set all vertices of the
polygon relative to the center point of the sprite, so things matched
up. Any suggestions for how to do this in Mekanimo?

Thanks,

--Ray Wenderlich, Razeware LLC

Fahri

unread,
Dec 19, 2010, 2:58:21 PM12/19/10
to Mekanimo
Hi Ray,

I am not sure if this is the cause of the problem you are having but I
think it is worth mentioning here. Mekanimo has a setting called
canvas.ppu. ppu means pixels per units and default value is 16.
Different engines use different values. Many Cocos2D users use 30 for
this value. You should set this value at the beginning of your
session and then create your polygon to match your sprite. This way
when you export the code, polygon dimensions and sprite pixels match
properly.

Mekanimo's sprite engine, matches the sprite center (some other
engines use upper left corner for example) and polygon cg (center of
gravity) by default. The offset values are defined between these two
points. For rectangles and circles there is no issue since their CGs
are at their center but a polygon's CG may not match the sprite's
center point. To address this issue you can either use sprite offsets
like Mekanimo does or pad your sprite with transparent pixels.

I am not familiar with vertex helper but will check it out.

I have a feeling that I am misunderstanding the exact problem you are
having so feel free to give me some concrete examples.

Fahri

Razeware LLC

unread,
Dec 19, 2010, 5:55:53 PM12/19/10
to Mekanimo
Hi Fahri,

Thanks again for the fast response!

Yeah I'm aware of the ppu setting (which is quite useful btw, thanks
for putting that in).

But that's not the problem - the problem is what you mentioned (the
sprite center not necessarily matching up with the polygon's center of
gravity, which is auto-calculated by Mekanimo). I can get it to show
up OK in Mekanimo by applying a sprite offset, but then when I
generate the C++ code, the polygon vertices aren't set up so that they
would be centered around a sprite applied to it.

As an example, there's a sprite I'm trying to trace here:

http://www.razeware.com/downloads/crow2_body.png

I'd like to end up somehow with C++ code defining a Box2D polygon body
that would be centered around that sprite. If there's no way to do
this in Mekanimo, I can work around that by editing the C++ code to
make it apply an offset to each vertex of the polygon, but I just
wanted to check if there was a way to fix/workaround this.

--Ray

Fahreddın Basegmez

unread,
Dec 19, 2010, 7:02:24 PM12/19/10
to meka...@googlegroups.com
On Sun, Dec 19, 2010 at 5:55 PM, Razeware LLC <razew...@gmail.com> wrote:
> Hi Fahri,
>
> Thanks again for the fast response!
>
> Yeah I'm aware of the ppu setting (which is quite useful btw, thanks
> for putting that in).
>
> But that's not the problem - the problem is what you mentioned (the
> sprite center not necessarily matching up with the polygon's center of
> gravity, which is auto-calculated by Mekanimo).  I can get it to show
> up OK in Mekanimo by applying a sprite offset, but then when I
> generate the C++ code, the polygon vertices aren't set up so that they
> would be centered around a sprite applied to it.
>
> As an example, there's a sprite I'm trying to trace here:
>
> http://www.razeware.com/downloads/crow2_body.png
>
> I'd like to end up somehow with C++ code defining a Box2D polygon body
> that would be centered around that sprite.  If there's no way to do
> this in Mekanimo, I can work around that by editing the C++ code to
> make it apply an offset to each vertex of the polygon,

Wouldn't that shift the CG as well? What engine are you using? Maybe
I can find out what others doing about similar issues.

> but I just
> wanted to check if there was a way to fix/workaround this.

There is an ugly workaround. Create a not so small circle and attach
your sprite to this circle. Then create a polygon by tracing your
sprite. Weld the circle and the polygon together. Finally reduce the
circle's radius to a small value without changing its position.
Circle will be inside the polygon and won't change the collision
behavior. If you wish you can reduce the circle's density value so
that the circle doesn't change the composite object's dynamic
characteristics much either. The resulting code will have a rigid
body with two shapes. If the engine you are using let's you assign
sprites to shapes (Mekanimo does) then use the circle for your sprite
position.

If you find a more elegant solution to this issue please share it with
us. That's a very good looking crow btw.

Fahri

> --
> You received this message because you are subscribed to the Google Groups "Mekanimo" group.
> To post to this group, send email to meka...@googlegroups.com.
> To unsubscribe from this group, send email to mekanimo+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mekanimo?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages