Function
World:update( dt )
When this function is called, the physics simulation is run according to the specified timestep.
Synopsis
World:update( dt )
Arguments
dt The time since last frame.
Returns
(Nothing)
Examples
Example 100: Mini Physics
  1. -- Example: Mini Physics 
  2.  
  3. function load() 
  4.  
  5.    -- Create a world with size 2000 in every direction. 
  6.    world = love.physics.newWorld(20002000
  7.    world:setGravity(050
  8.  
  9.    -- Create the ground body at (0, 0) with mass 0. 
  10.    ground = love.physics.newBody(world, 000
  11.     
  12.    -- Create the ground shape at (400,500) with size (600,10). 
  13.    ground_shape = love.physics.newRectangleShape(ground, 40050060010
  14.  
  15.    -- Load the image of the ball. 
  16.    ball = love.graphics.newImage("images/love-ball.png"
  17.  
  18.    -- Create a Body for the circle. 
  19.    body = love.physics.newBody(world, 400200
  20.     
  21.    -- Attatch a shape to the body. 
  22.    circle_shape = love.physics.newCircleShape(body, 28
  23.     
  24.    -- Calculate the mass of the body based on attatched shapes. 
  25.    -- This gives realistic simulations. 
  26.    body:setMassFromShapes() 
  27.  
  28. end 
  29.  
  30. function update(dt) 
  31.    -- Update the world. 
  32.    world:update(dt) 
  33. end 
  34.  
  35. function draw() 
  36.    -- Draws the ground. 
  37.    love.graphics.polygon(love.draw_line, ground_shape:getPoints()) 
  38.  
  39.    -- Draw the circle. 
  40.    love.graphics.draw(ball,body:getX(), body:getY(), body:getAngle()) 
  41. end 
  42.  
  43. function keypressed(k) 
  44.    if k == love.key_space then 
  45.       -- Apply a random impulse 
  46.       body:applyImpulse(100000-math.random(0200000), 0
  47.    end 
  48. end 
Copyright © 2006-2008 LÖVE Development Team.