OK I admit defeat.
I'm running the CreateAllAsteroids function (see below), but AppGameKit seems to get stuck at some point creating one of the new sprites.
What's weird is that it will crash at random points. The function attempts to create 24 sprites from the same image, but sometimes it will crash on the first sprite, sometimes on the 18th, sometimes on the 6th.
I'm really lost with this one so any help will be great.
I'm running v108.19 on win7.
The functions are below.
function CreateAllAsteroids()
//creates all asteroid objects
for a=0 to MaxAsteroids
CreateNewAsteroid(a,0)
next a
endfunction
function CreateNewAsteroid(AsteroidID as integer, KnownMass as float)
//creates a new asteroid object
a = AsteroidID
//delete old sprite if exists
spriteid = asteroid[a].spriteid
if getspriteexists(spriteid)=1 then deletesprite(spriteid)
//CREATE SPRITE
//pick an asteroid image
ImageID = AsteroidImg
repeat
spriteid = createsprite(ImageID)
asteroid[a].spriteid = spriteid
if getspriteexists(asteroid[a].spriteid)=0
deletesprite(spriteid)
print("lost sprite "+str(spriteid))
endif
until getspriteexists(asteroid[a].spriteid)=1
if DevMode=1
print("Astroid "+str(a)+" sprite created.")
endif
fixspritetoscreen(spriteid,0)
rscale# = random(200,600) * 0.01
setspritescale(spriteid,rscale#,rscale#)
setspriteoffset(spriteid,getspritewidth(spriteid)/2,getspriteheight(spriteid)/2)
setspritedepth(spriteid,5000)
PositionOK = 1
posangle# = 1.0 * random(0,360)
Radius# = AstSpawnDist * random(100,200) * 0.01
xpos# = getspritexbyoffset(PlrDroid[0].spriteid) + (Radius# * sin(posangle#))
ypos# = getspriteybyoffset(PlrDroid[0].spriteid) + (Radius# * cos(posangle#))
if DevMode=1
print("Astroid "+str(a)+" PosAngle:"+str(posangle#,1)+", X:"+str(xpos#,1)+", Y:"+str(ypos#,1))
endif
setspritepositionbyoffset(spriteid,xpos#,ypos#)
posangle# = 1.0 * random(0,360)
setspriteangle(spriteid,posangle#)
setspriteshape(spriteid,3)
setspritephysicson(spriteid,2)
if DevMode=1
print("Astroid "+str(a)+" Physics ON")
endif
//set initial velocity
posangle# = 1.0 * random(0,360)
vmax# = 1.0 * random(0,20)
vx# = (vmax# * sin(posangle#))
vy# = (vmax# * cos(posangle#))
setspritephysicsvelocity(spriteid,vx#,vy#)
if DevMode=1
print("Astroid "+str(a)+" Velocity Set to "+str(vx#,1)+","+str(vy#,1))
endif
setspritevisible(spriteid,1)
//ASTEROID STATS
asteroid[a].life = random(20000,40000)
if KnownMass>0
asteroid[a].mass = KnownMass
else
//random mass
asteroid[a].mass = random(5000,105000)*0.001
endif
SetAsteroidElements(a)
if DevMode=1
print("Astroid "+str(a)+" elements set.")
sync()
endif
endfunction