Attaching multiple shapes to fixture and setting an image
Posted: Sun Aug 12, 2012 5:24 pm
I created a code from this example. https://love2d.org/wiki/Tutorial:Physics
I want to replace the ball object so I created a pig object, I used a program to compute multiple polygon shapes that will be used for my particular object.
Here is my image. Here is my code
I tried to store the ploygon shapes into a table/array. Then loop through each shape and add a new fixture for each shape. However I get this error on this line:
Incorrect parameter type: expected userdata
When drawing the ball , the example used this code.
Now, how do I draw my image with the multiple polygons set? I just don't want it to be a plain circle even though this pig image could actually be a circle.
To make this simple I want to accomplish something like the image below:
I want to replace the ball object so I created a pig object, I used a program to compute multiple polygon shapes that will be used for my particular object.
Here is my image. Here is my code
Code: Select all
imagePig = love.graphics.newImage("queen_pig.png")
--let's create the pig
objects.pig = {}
objects.pig.body = love.physics.newBody(world, 1024/2, 768/2, "dynamic")
objects.pig.image = imagePig
objects.pig.shapes = {
love.physics.newPolygonShape(9, 46, 8, 44, 8, 38, 14, 36, 11, 46),
love.physics.newPolygonShape(-33, 14, -31, 13, -21, 22, -33, 17),
love.physics.newPolygonShape(23, 22, 23, 26, 21, 34, 5, 27, 20, 20),
love.physics.newPolygonShape(-32, 29, -36, 24, -36, 19, -33, 17, -21, 22, -26, 29),
love.physics.newPolygonShape(28, 17, 20, 20, 28, 12),
love.physics.newPolygonShape(-17, 37, -17, 28, -14, 25, -3, 27, -3, 37, -6, 40, -12, 40),
love.physics.newPolygonShape( 8, 38, 7, 33, 14, 36),
love.physics.newPolygonShape(26, 28, 26, 30, 21, 34, 23, 26),
love.physics.newPolygonShape(5, 31, 5, 27, 21, 34, 14, 36 , 7, 33),
love.physics.newPolygonShape( 21, 41, 19, 41, 14, 36, 21, 34),
love.physics.newPolygonShape(-17, 25, -21, 22, -37, -19, 31, 10, 28, 12, -14, 25),
love.physics.newPolygonShape(-29, -29, -12, -35, 10, -35, 21, -32, 31, 10, -37, -19 ),
love.physics.newPolygonShape(32, 34, 32, 36, 21, 34, 26, 30),
love.physics.newPolygonShape( -36, 8, -39, 0, -39, -11 , -37, -19, -21, 22, -31, 13),
love.physics.newPolygonShape(34, -21, 37, -12, 36, 1, 31, 10, 21, -32, 28, -28),
love.physics.newPolygonShape(20, 20, 5, 27, -3, 27, -14, 25, 28, 12)
}
for i=0, table.getn(objects.pig.shapes) do
objects.pig.fixtures[i] = love.physics.newFixture(objects.pig.body, objects.pig.shapes[i],2)
objects.pig.fixtures[i]:setRestitution(0.9) --let the pig to bounce
end
Code: Select all
objects.pig.fixtures[i] = love.physics.newFixture(objects.pig.body, objects.pig.shapes[i],2)
When drawing the ball , the example used this code.
Code: Select all
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
To make this simple I want to accomplish something like the image below: