Attach a sprite to the physics body

Hi Guys,

I have read the physics 101 but there has to be a bit missing, it doesn’t show the line where it adds the img to the circle…

Please help!! @Simeon



any help @Anyone lol

@Simeon please help :frowning:

.@Chezzy - have a look at the MineSweeper code at:

In the menu screen I attach a mine sprite to the physics object.

You can see what it looks like here:

I can see the sprite command but how does it know what body ? @Reefwing

.@Chezzy - I extended the PhysicsDebugDraw() class which comes with the Physics Demo in Codea. You can download the modified class from here:

I attached the image to the Circle object because my sprite was round. When you create the circle, make it the same size as your sprite. I modified the PhysicsDebugDraw:draw() function so that if an image had been set (i.e. spriteImage was not nil), it draws that sprite instead of a circle. You should be able to do something similar for what you need.

In your main you need to assign the sprite by doing something like:

function setup()

    img = readImage("Your Image")
    physicsDraw = PhysicsDebugDraw()
    physicsDraw.spriteImage = img

    -- You can then create some objects
    defaultGravity = physics.gravity()
    createBox(WIDTH/2, 100, 30, 30)
    createCircle(WIDTH/2 + 50, HEIGHT, 30)
    createRandPoly(WIDTH/2 + 150, 120)


function draw()

-- The next function is optional. Use it if you want to see the collision points
function collide(contact)