2DPhysics_Joints.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. screen = PhysicsScreen(10, 50)
  2. ceiling = ScreenShape(ScreenShape.SHAPE_RECT, 640, 20)
  3. ceiling:setColor(0.0, 0.0, 0.0, 1.0)
  4. ceiling:setPosition(640/2, 10)
  5. screen:addPhysicsChild(ceiling, PhysicsScreenEntity.ENTITY_RECT, true)
  6. -- Revolute Joint
  7. shape = ScreenShape(ScreenShape.SHAPE_RECT, 10, 30)
  8. shape:setPosition(150, 20+15)
  9. screen:addPhysicsChild(shape, PhysicsScreenEntity.ENTITY_RECT, false)
  10. screen:createRevoluteJoint(shape, ceiling, 0, -15)
  11. screen:applyImpulse(shape, 10, 0)
  12. -- Distance Joint
  13. shape = ScreenShape(ScreenShape.SHAPE_RECT, 10, 30)
  14. shape:setPosition(250, 20+25)
  15. screen:addPhysicsChild(shape, PhysicsScreenEntity.ENTITY_RECT, false)
  16. screen:createDistanceJoint(shape, ceiling, false)
  17. screen:applyImpulse(shape, 200, 0)
  18. line = ScreenLine.ScreenLineBetweenEntities(shape, ceiling)
  19. line:setColor(1.0, 0.0, 0.0, 1.0)
  20. screen:addChild(line)
  21. -- Prismatic Joint
  22. shape = ScreenShape(ScreenShape.SHAPE_RECT, 10, 30)
  23. shape:setPosition(450, 20+25)
  24. screen:addPhysicsChild(shape, PhysicsScreenEntity.ENTITY_RECT, false)
  25. screen:createPrismaticJoint(ceiling, shape, Vector2(0,1), 0,0, false, 100, 0, true)
  26. lineAnchor = ScreenEntity()
  27. lineAnchor:setPosition(450,10)
  28. line = ScreenLine.ScreenLineBetweenEntities(shape, lineAnchor)
  29. line:setColor(0.0, 1.0, 0.0, 1.0)
  30. screen:addChild(line)