|
|
Module
love.physics
The physics module is capable of deteting collisions between objects, and simulate
a realistic responses.
The module is currently based on Box2D. The original
naming scheme is kept, and most of the functionality avaliable in Box2D is avaliable in LÖVE,
so you can also take a look at the
Box2D User Manual for detailed
documentation.
Some limitations to keep in mind:
- Only convex shapes are supported.
- The max vertex count for on a single polygon is 8.
- There are 16 shape categories.
Functions
|
newWorld( w, h )
|
Creates a new World.
|
|
newWorld( lx, ly, ux, uy, gx, gy, sleep )
|
Creates a new World.
|
|
|
|
|
newBody( world )
|
Creates a new Body.
|
|
newBody( world, x, y )
|
Creates a new Body with some position.
|
|
newBody( world, x, y, m )
|
Creates a new Body with some position and mass.
|
|
|
|
|
newCircleShape( body, radius )
|
Creates a new CircleShape.
|
|
newCircleShape( body, x, y, radius )
|
Creates a new CircleShape with an offset.
|
|
|
|
|
newRectangleShape( body, w, h )
|
Creates a rectangle.
|
|
newRectangleShape( body, x, x, w, h )
|
Creates a new rectangle with an offset.
|
|
newRectangleShape( body, x, x, w, h, angle )
|
Creates a new rectangle with offset and orientation.
|
|
|
|
|
newPolygonShape( body, ... )
|
Creates a new PolygonShape.
|
|
|
|
|
newDistanceJoint( body1, body2, x1, y1, x2, y2 )
|
Creates a new DistanceJoint.
|
|
newRevoluteJoint( body1, body2, x, y )
|
Creates a new RevoluteJoint.
|
|
newPrismaticJoint( body1, body2, x, y, ax, ay )
|
Creates a new PrismaticJoint.
|
|
newMouseJoint( body, x, y )
|
Creates a new MouseJoint
|
Examples
Example 100: Mini Physics
-
-
- function load()
-
-
- world = love.physics.newWorld(2000, 2000)
- world:setGravity(0, 50)
-
-
- ground = love.physics.newBody(world, 0, 0, 0)
-
-
- ground_shape = love.physics.newRectangleShape(ground, 400, 500, 600, 10)
-
-
- ball = love.graphics.newImage("images/love-ball.png")
-
-
- body = love.physics.newBody(world, 400, 200)
-
-
- circle_shape = love.physics.newCircleShape(body, 28)
-
-
-
- body:setMassFromShapes()
-
- end
-
- function update(dt)
-
- world:update(dt)
- end
-
- function draw()
-
- love.graphics.polygon(love.draw_line, ground_shape:getPoints())
-
-
- love.graphics.draw(ball,body:getX(), body:getY(), body:getAngle())
- end
-
- function keypressed(k)
- if k == love.key_space then
-
- body:applyImpulse(100000-math.random(0, 200000), 0)
- end
- end
|