**Update**
I've updated this simple code to now write to a file (assumes you're running Windows) You still have to manually load the image by changing the code and set its size and position to where you want it.
It always has a line drawn from 0,0 something I've not been able to figure out why, so would love to know how to fix that, but if you click and draw a shape around your sprite, the code that gets generated works as expected. Has saved me hours of messing about with coordinates. You also have to set the Virtual Resolution to the same as your project.
// Project: DrawCollisions
// Created: 2020-10-26 by Paxi
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "DrawCollisions" )
SetWindowSize( 600, 900, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 120, 200 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
/////////////////////////////////////////////////////////////////////////////////////////
//Load in the Sprite that needs the coordinates for the collision box. Make sure the
//Virtual Res is set the same as your project.
//////////////////////////////////////////////////////////////////////////////////////
Global thisSpriteID = 2//Manually set the sprite ID
Global chainID = 2 ///Manually set the chainID
yourSprite = LoadImage ("YOURIMAGE.png") //User add your own image here
CreateSprite (thisSpriteID, yourSprite)
SetSpriteSize(thisSpriteID,0,0) //Set your Sprites size and position
SetSpritePosition(thisSpriteID,0,0)
///////////////////////////////////////////////////////////////////////////////////
//arrays to store the X Y coordinates
Dim pointX[1,20]
Dim pointY[1,20]
Global p = 0//keep count of the points
firstclick = 0
do
x1 = GetPointerX()
y1 = GetPointerY()
If GetPointerPressed() = 1
inc p
pointX[1,p] = x1
pointY[1,p] = y1
saveCoords()
Endif
If p = 12
Print("MAXIMUM POINTS REACHED!")
p = 11
endif
For x = 1 to p
DrawLine(pointX[1,x], pointY[1,x] , pointX[1,x+1] , pointY[1,x+1], 255,0,0)
ax = pointX[1,x]
ax = ax - GetSpriteXByOffset(thisSpriteID)
ay = pointY[1,x]
ay = ay - GetSpriteYByOffset(thisSpriteID)
Print("Points " +str(p))
Print("X " +str(ax))
Print("Y " +str(ay))
Next x
Sync()
loop
Function saveCoords()
px as integer
py as integer
aString$ as string
file = OpenToWrite("raw:C:\SpriteChainCoords.txt",0)
For x = 1 to p
px = pointX[1,x]
px = px - GetSpriteXByOffset(thisSpriteID)
py = pointY[1,x]
py = py - GetSpriteYByOffset(thisSpriteID)
//Write the SpriteChain code with our coords, sprite ID and Chain ID
//If you want a closed loop chain change the 0 to a 1 in the line below
aString$ = "SetSpriteShapeChain("+str(thisSpriteID)+", "+str(p) +", "+str(x-1) +", 0, "+str(px) +", "+str(py) +", "+str(chainID)+")"
Writeline(file,aString$)
Next x
CloseFile ( file )
Endfunction