Scaling polygons in Mekanimo

9 views
Skip to first unread message

Rod

unread,
Sep 22, 2009, 2:34:58 PM9/22/09
to Mekanimo
Fahri,

We need a way to specify the Pixels to Meter ratio inside of Mekanimo
so that the physics models can matching dimensions to the graphics.
For example, say in game we have a car sprite with dimensions:
Width: 90 pixels
Height: 30 pixels

The Pixel to Meter ration is 30 pixels to 1 meter
If we draw the car as a simple rectangle in Box2D, it should have:
Width: 3 meters
Height: 1 meter

Here is what I have tried to do in Mekanimo:
Created a rectangle with the correct dimensions (3x1) and added the
car sprite to it. Note the Sprite appears larger then the rectangle.
On top of the rectangle, I have attempted to trace the complex polygon
shape of the car. Each time the scale comes out incorrect, this may be
due to the way Mekanimo renders the sprite on the sheet/layer/editor.
It appears to render the sprites (PNGs in my case) larger then their
actual size.

As a future feature, it would be great to have Sprites as a layer in
the editor or as their own shapes, to aid in tracing the graphics
shapes/contours to Box2D geometry.
Thank you,
Rod

Fahri

unread,
Sep 22, 2009, 11:09:59 PM9/22/09
to Mekanimo
To change the pixels per meter (or whatever unit you would like to
use) you can set canvas.ppu (pixels per unit) property as shown below
from either the code editor or the Python interpreter. The default
value is 16 pixels per units.

>>> canvas.ppu = 30

This way when your 90x30 sprite appears in Mekanimo (make sure that
canvas scale is one, you can set this from the View -> Zoom ->
Originial size menu, and see the scale in the status bar) and you
create a rectangle by tracing it, you would end up with a 3x1 unit
length rectangle.

When the canvas scale is one, sprites appear in their original size,
when you have a scale factor other than one then Mekanimo scales the
sprites accordingly.

Zooming does not change the actual dimensions of the rigid bodies that
would be passed to the solver (in this case box2D) but just the way
they are displayed.
Reply all
Reply to author
Forward
0 new messages