Is there any way to make a physics body visible?

This would help make sure sprites, etc. match the physics body. I’m a newbie.


Physics bodies are not visible. You have to assign something ( ellipse, rect, sprite, etc. ) to the physics bodies x,y variables to see where they’re at.

I feared as much. Thanks.

For a perfect approach, you can draw a set of lines using the sama data as the physics body.

Or you can generate a mesh by using the “triangulate” function to triangulate the points of the body. But that only works with polygons.

God, the physics documentation of Codea is in tatters. How can you return all the points in a physics body polygon?

Oh yeah, also, here’s some example code:

-- draw phys body

-- Use this function to perform your initial setup
function setup()
    pointsList = {}
    table.insert(pointsList, vec2(-10, 10))
    table.insert(pointsList, vec2( 10, 10))
    table.insert(pointsList, vec2( 10,-10))
    table.insert(pointsList, vec2(-10,-10))
    body = physics.body(POLYGON, unpack(pointsList))
    body.x = WIDTH * 0.5
    body.y = HEIGHT * 0.5

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness


    -- Do your drawing here
    translate(body.x, body.y)

function drawLines(linePoints)
    for i in pairs(linePoints) do
        j = i + 1
        if not linePoints[j] then
            j = 1
        line(linePoints[i].x, linePoints[i].y, linePoints[j].x, linePoints[j].y)

There’s actually a debug draw function the the physics example which can draw every body type. I’ve adapted it to work better, I’m on my iPhone. Anyways, look at the mesh triangulate function for filled polygon physics bodies.

@Causeless body.points returns all points in a body, it is read only though.

Um, guys… There’s a Physics Lab example built-in to Codea with a class titled PhysicsDebugDraw that draws physics bodies…

Edit: Sorry, missed @Zoyt pointed this out already.