I thought I'd share a simple object maker with you all. You can use it to build polygon shapes for your game.
All you do is load the image for your object and click where you want the vertices for the polygon shape. It will produce a simple text file which you can hard code into your game or load from a folder when your game starts.
You just need to remember to pick points in a clockwise direction and don't make concave shapes!! You can add additional fixtures by pressing (+) that's the one next to backspace.
I am working on a simple algorithm to check for concave points being added so it could start a new fixture automatically but it works as it is.
Here's some sample code to load an object as a static poly shape:
rem file$=image file
if file exist(file$)=1
`get b2d dimensions
open to read 1,file$
read string 1,dat$
read string 1,dat1$
read string 1,dat2$
read string 1,dat3$
density#=val(dat1$)
friction#=val(dat2$)
bounce#=val(dat3$)
read string 1,dat$
global numverts
numverts=val(dat$)
dim tempshape(numverts,2)
a=0
while a<numverts
inc a
read string 1,dat1$
read string 1,dat2$
tempshape(a,1)=val(dat1$)
tempshape(a,2)=val(dat2$)
endwhile
endif
close file 1
CreateStaticPoly(image,x#,y#,n,world,density#,friction#,bounce#,ang#)
function CreateStaticPoly(image,x#,y#,n,world,d#,f#,r#,ang#)
n=n
o=find_free_object()
if o>0
f#=0.2
body = b2CreateBody(world, b2BodyType_Static(), x#, y#, ang#)
b2SetBodyImage body, image, f#
s=1
while s<n
ox#=tempshape(s,1)
count=0
while ox#>-999
inc count
ox#=tempshape(s+count,1)
endwhile
select count
case 3
`create shape
x1#=tempshape(s,1)*f#:y1#=tempshape(s,2)*f#
x2#=tempshape(s+1,1)*f#:y2#=tempshape(s+1,2)*f#
x3#=tempshape(s+2,1)*f#:y3#=tempshape(s+2,2)*f#
shape=b2CreatePolygonShape(x1#,y1#,x2#,y2#,x3#,y3#)
endcase
case 4
`create shape
x1#=tempshape(s,1)*f#:y1#=tempshape(s,2)*f#
x2#=tempshape(s+1,1)*f#:y2#=tempshape(s+1,2)*f#
x3#=tempshape(s+2,1)*f#:y3#=tempshape(s+2,2)*f#
x4#=tempshape(s+3,1)*f#:y4#=tempshape(s+3,2)*f#
shape=b2CreatePolygonShape(x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#)
endcase
case 5
`create shape
x1#=tempshape(s,1)*f#:y1#=tempshape(s,2)*f#
x2#=tempshape(s+1,1)*f#:y2#=tempshape(s+1,2)*f#
x3#=tempshape(s+2,1)*f#:y3#=tempshape(s+2,2)*f#
x4#=tempshape(s+3,1)*f#:y4#=tempshape(s+3,2)*f#
x5#=tempshape(s+4,1)*f#:y5#=tempshape(s+4,2)*f#
shape=b2CreatePolygonShape(x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#,x5#,y5#)
endcase
case 6
`create shape
x1#=tempshape(s,1)*f#:y1#=tempshape(s,2)*f#
x2#=tempshape(s+1,1)*f#:y2#=tempshape(s+1,2)*f#
x3#=tempshape(s+2,1)*f#:y3#=tempshape(s+2,2)*f#
x4#=tempshape(s+3,1)*f#:y4#=tempshape(s+3,2)*f#
x5#=tempshape(s+4,1)*f#:y5#=tempshape(s+4,2)*f#
x6#=tempshape(s+5,1)*f#:y6#=tempshape(s+5,2)*f#
shape=b2CreatePolygonShape(x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#,x5#,y5#,x6#,y6#)
endcase
case 7
`create shape
x1#=tempshape(s,1)*f#:y1#=tempshape(s,2)*f#
x2#=tempshape(s+1,1)*f#:y2#=tempshape(s+1,2)*f#
x3#=tempshape(s+2,1)*f#:y3#=tempshape(s+2,2)*f#
x4#=tempshape(s+3,1)*f#:y4#=tempshape(s+3,2)*f#
x5#=tempshape(s+4,1)*f#:y5#=tempshape(s+4,2)*f#
x6#=tempshape(s+5,1)*f#:y6#=tempshape(s+5,2)*f#
x7#=tempshape(s+6,1)*f#:y7#=tempshape(s+6,2)*f#
shape=b2CreatePolygonShape(x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#,x5#,y5#,x6#,y6#,x7#,y7#)
endcase
case 8
`create shape
x1#=tempshape(s,1)*f#:y1#=tempshape(s,2)*f#
x2#=tempshape(s+1,1)*f#:y2#=tempshape(s+1,2)*f#
x3#=tempshape(s+2,1)*f#:y3#=tempshape(s+2,2)*f#
x4#=tempshape(s+3,1)*f#:y4#=tempshape(s+3,2)*f#
x5#=tempshape(s+4,1)*f#:y5#=tempshape(s+4,2)*f#
x6#=tempshape(s+5,1)*f#:y6#=tempshape(s+5,2)*f#
x7#=tempshape(s+6,1)*f#:y7#=tempshape(s+6,2)*f#
x8#=tempshape(s+7,1)*f#:y8#=tempshape(s+7,2)*f#
shape=b2CreatePolygonShape(x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#,x5#,y5#,x6#,y6#,x7#,y7#,x8#,y8#)
endcase
endselect
`create fixture
fixture=b2CreateFixture(body,shape,d#,f#,r#)
s=s+count+1
endwhile
endif
endfunction body
Sorry if the code is incomplete but it's just an example of how you might use it. Works nicely in my game...
The text file format is as follows:
3 - an integer for object type in my game (ignore)
0.5 - density#
0.20000000298 - friction#
0.00999999977648 - restitution#
11 - number of vertex points (+1 for my own use)
7 - vertex position x
-100 - vertex position y
7 - vertex position x... etc.
33
-10
59
-9
-26
-1111 - start of a new fixture
-999 - ignore
8
33
14
56
15
88
-14
98
-10
57
-999 - end of object vertices
-999
If anyone wants any help using it just shout...
Here's a screenshot of it in action: