Defold native extension for the Chipmunk 2D physics engine.
You can use the extension in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:
https://github.com/britzl/chipmunk2d-defold/archive/master.zip
Or point to the ZIP file of a specific release.
HTML5 demo of the example project here: https://britzl.github.io/Chipmunk2D/
The extension binds the individual methods of the Chipmunk 2D API. It should be possible to translate most of the official Chipmunk 2D manuals and demos when working with this extension.
Create a new space
PARAMETERS
gravity_x
(number) - Horizontal gravity affecting bodies in this spacegravity_y
(number) - Vertical gravity affecting bodies in this space
RETURNS
space
(userdata) - The created space
Create a new circle body
PARAMETERS
radius
(number) - Radius of the circlemass
(number) - Mass of the body
RETURNS
body
(userdata) - The created body
Create a new box body
PARAMETERS
width
(number) - Width of the boxheight
(number) - Height of the boxmass
(number) - Mass of the body
RETURNS
body
(userdata) - The created body
Create a static body
RETURNS
body
(userdata) - The created body
Create a new circle shape
PARAMETERS
body
(userdata) - The body this shape should be attached toradius
(number) - Radius of the circle
RETURNS
shape
(userdata) - The created shape
Create a new box shape
PARAMETERS
body
(userdata) - The body this shape should be attached towidth
(number) - Width of the boxheight
(number) - Height of the boxradius
(number) - Radius of the rounded corners
RETURNS
shape
(userdata) - The created shape
Create a new segment shape
PARAMETERS
body
(userdata) - The body this shape should be attached toax
(number) - Horizontal position of endpoint aay
(number) - Vertical position of endpoint abx
(number) - Horizontal position of endpoint bby
(number) - Vertical position of endpoint bthickness
(number) - Thickness of the segment
RETURNS
shape
(userdata) - The created shape
Create a new damped spring
PARAMETERS
body1
(userdata) - The first body to connectbody2
(userdata) - The second body to connecta1x
(number) - Horizontal position of the anchor point on the first bodya1y
(number) - Vertical position of the anchor point on the first bodya2x
(number) - Horizontal position of the anchor point on the second bodya2y
(number) - Vertical position of the anchor point on the second bodyrest_length
(number) - Rest length of the springstiffness
(number) - Stiffness of the spring in force/distancedamping
(number) - Damping of the spring
RETURNS
constraint
(userdata) - The created constraint
Create a new slide joint
PARAMETERS
body1
(userdata) - The first body to connectbody2
(userdata) - The second body to connecta1x
(number) - Horizontal position of the anchor point on the first bodya1y
(number) - Vertical position of the anchor point on the first bodya2x
(number) - Horizontal position of the anchor point on the second bodya2y
(number) - Vertical position of the anchor point on the second bodymin
(number) - Minimum distance the joint will maintain between the anchorsmax
(number) - Maximum distance the joint will maintain between the anchors
RETURNS
constraint
(userdata) - The created constraint
Set the friction of a shape
PARAMETERS
shape
(userdata) - Shape to set friction forfriction
(number) - Friction of the shape
Set the elasticity of a shape
PARAMETERS
shape
(userdata) - Shape to set friction forelasticity
(number) - Elasticity of the shape
Add a body to a space
PARAMETERS
space
(userdata) - Space to add body tobody
(userdata) - The body to add
Add a shape to a space
PARAMETERS
space
(userdata) - Space to add body toshape
(userdata) - The shape to add
Add a constraint to a space
PARAMETERS
space
(userdata) - Space to add body toconstraint
(userdata) - The constraint to add
Step/update the physics simulation of a space
PARAMETERS
space
(userdata) - Space to step/updatedt
(number) - The delta time of the update
Set the position of a body
PARAMETERS
body
(userdata) - Body to set position forx
(number) - Horizontal position of the bodyy
(number) - Vertical position of the body
Get the position of a body
PARAMETERS
body
(userdata) - The body to get position for
RETURNS
x
(number) - Horizontal positiony
(number) - Vertical position
Get the rotation of a body
PARAMETERS
body
(userdata) - The body to get rotation for
RETURNS
angle
(number) - Rotation angle in radians
Get the velocity of a body
PARAMETERS
body
(userdata) - The body to get velocity for
RETURNS
x
(number) - Horizontal velocityy
(number) - Vertical velocity