Recycling of Types

Blitz3D Forums/Blitz3D Beginners Area/Recycling of Types

well, why don't you just free the entity, then delete the object

FreeEntity thisdrone\dronehandle
delete thisdrone.drone


then create a new one when you need it, or am i missing something?

try this
Graphics3D 800,600
SetBuffer BackBuffer()


light=CreateLight()
eship=CreateSphere()
PositionEntity eship,-30,0,0

camera=CreateCamera()
PositionEntity camera,0,0,-20

Gosub setup

While Not KeyHit(1)

	If KeyDown(200) Then Gosub createnewship
	
	
	
	Gosub updateships
	
	UpdateWorld
	RenderWorld
	Text 0,0," press up key to generate enemy craft"
	Flip
Wend
	
End


.updateships
	For enemy.ship=Each ship
	enemy\y=enemy\y-enemy\speed
	PositionEntity enemy\entity,enemy\x,enemy\y,0
	If enemy\y<-9 Then
						FreeEntity enemy\entity:Delete enemy.ship; free the entity then delete the type object
	End If
	Next
Return



.createnewship
	enemy.ship=New ship
	enemy\entity=CopyEntity(eship); copy the eship entity
	enemy\x=Rnd(-10,10)
	enemy\y=9
	enemy\speed=Rnd(0.1,0.5)
Return

.setup
	Type ship
	Field entity
	Field x,y#
	Field speed#
	End Type
Return