Hi all. I started this tool on a request thread by bjadams here:
http://forum.thegamecreators.com/?m=forum_view&t=192237&b=41
Now finished and open source!!
DOWNLOAD V1.0.1 updated 12th March 2012!
Version edits:
Added Zoom buttons and view joystick for small shapes
Usage:
1-Put your image into the "media/input" folder
2-Start the app
3-Randomise the background colour using the bottom right button if you can't see the image properly
4-Draw your shapes
5-Export using the "EXPORT" button. This creates a file called "yourImage.shp" for an image called "yourImage.png" in the "...\Documents\AGK\C_AGK_temp_Projects_ShapeUp_ShapeUpexe" folder.
6-Put the "loadPhysicsSprite()" function into your game after the loop
7-Put the image and "shp" file in your game's media folder
8-Call the load function to create a physics sprite using the shape you saved!
Use convex shapes only, built up in a clockwise direction and no more than 12 vertices per shape but you can add as many shapes as you like (I think)
Here is a load shape function that works with the output:
function loadSpriteShape(shapeFile$, spr)
rem read the contents and create the shape
i=getSpriteImageID(spr)
scaleX# = (getSpriteWidth(spr)*pw)/(getImageWidth(i)*pw)
scaleY# = (getSpriteHeight(spr)*ph)/(getImageHeight(i)*ph)
filenum = openToRead(shapeFile$)
nul$ = readLine(filenum)
shapes = val(readLine(filenum))
dim shp[shapes] as dataType
points=0
for i=1 to shapes
nul$ = readLine(filenum)
nul$ = readLine(filenum)
totalnum = val(readLine(filenum))
shp[i].s = points+1
shp[i].f = points+totalnum
for x=1 to totalnum
points = points+1
dim point[points] as pointType
nul$ = readLine(filenum)
pntx# = FloatVal(readLine(filenum))*scaleX#
pnty# = FloatVal(readLine(filenum))*scaleY#
addSpriteShapePolygon(spr,totalnum,x-1,pntx#,pnty#)
point[points].x = pntx#+sw*0.5
point[points].y = pnty#+sh*0.5
next
next
closeFile(filenum)
endfunction
Here is a "loadPhysicsSprite" function:
function loadPhysicsSprite(width#, height#, xpos#, ypos#, imageName$, phyType, imagenum)
rem get the file
Tfile$=left(imageName$,len(imageName$)-3)+"shp"
rem load the image
if imagenum<=0
imagenum = loadImage(imageName$)
else
loadImage(imagenum,imageName$)
endif
rem create the sprite
scaleX# = width# / getImageWidth(imagenum)
scaleY# = height# / getImageHeight(imagenum)
spr = createSprite(imagenum)
setSpriteSize(spr,width#,height#)
setSpriteOffset(spr,width#*0.5,height#*0.5)
setSpritePositionByOffset(spr,xpos#,ypos#)
setSpritePhysicsOn(spr,phyType)
setSpriteShape(spr,0)
rem read the contents and create the shape
filenum = openToRead(Tfile$)
nul$ = readLine(filenum)
shapes = val(readLine(filenum))
for i=1 to shapes
nul$ = readLine(filenum)
nul$ = readLine(filenum)
totalnum = val(readLine(filenum))
for x=1 to totalnum
nul$ = readLine(filenum)
pntx# = FloatVal(readLine(filenum))
pnty# = FloatVal(readLine(filenum))
addSpriteShapePolygon(spr,totalnum,x-1,pntx#*scaleX#,pnty#*scaleY#)
next
next
closeFile(filenum)
endfunction spr
function FloatVal(s$)
s1$=""
s2$=""
l = len(s$)
for c=1 to l
letter$=mid(s$,c,1)
if letter$="."
s2$=mid(s$,c+1,l-c)
exit
else
s1$=s1$+letter$
endif
next
v1=val(s1$)
v2#=val(s2$)
n=len(s2$)
if n>6
n=6
s2$=mid(s2$,1,6)
v2#=val(s2$)
endif
for i=1 to n
v2#=v2#*0.1
next
v#=v1+v2#
endfunction v#
Simples... ish...