Single surface help !

Blitz3D Forums/Blitz3D Programming/Single surface help !

Hi :)

Here is the code i have find : But i need two stuff

- Delete a sprite
- Hide a sprite

Anybody can help me ?

Global fpsindex#,fpstime#,fpsfold_millisecs#,fpsfps#,time,xyzturn

Type layer
	Field mesh
	Field count
	Field spritebank ; bank of sprites up to count
End Type

Type sprite
	Field x#,y#,z#
	Field r,g,b
	Field s#,a#
	Field verti[3]
	Field surf
End Type

;--------------------------------------------------------------------------------------------
Graphics3D 640,480,16,2
SetBuffer BackBuffer()
Global camera=CreateCamera()
CameraRange camera,1,9000
light=CreateLight(2)
PositionEntity light,1000,1000,-1000
;--------------------------------------------------------------------------------------------
fire=LoadTexture ("C:\Program Files\Blitz3D\samples\RobCummings\Bumpy\glow.bmp",2+48)

test=CreateLayer()
EntityTexture test,fire

;For i=0 To 1000
;	temp = AddSprite(test)
;	PositionSprite temp,Rnd(-500,500),Rnd(-500,500),Rnd(-500,500)
;Next

temp1 = AddSprite(test)
PositionSprite temp1,0,0,50

temp2 = AddSprite(test)
PositionSprite temp2,20,0,50



;--------------------------------------------------------------------------------------------
HidePointer
While Not KeyHit(1)


	;TransTex(fire,MilliSecs()*0.08)
	UpdateSprites()
	
	; Get the timer value
	T=MilliSecs() 
	
	; Mouse Look, every 25ms
	Time1=mouselook(camera,T,Time1,25)

	If MouseHit(1) Then
		AlphaSprite(temp1,0.1)
		AlphaSprite(temp2,0.1)
	EndIf
	
	; Movement
	If KeyDown(17) Then MoveEntity camera,0,0,1  ;W
	If KeyDown(31) Then MoveEntity camera,0,0,-1 ;S
	If KeyDown(30) Then MoveEntity camera,-1,0,0 ;A
	If KeyDown(32) Then MoveEntity camera,1,0,0  ;D

	UpdateWorld
	RenderWorld
	Text 0,0,fps()


	Flip 0
Wend
End

;--------------------------------------------------------------------------------------------

Function UpdateSprites()
;	For l.layer=Each layer
;		surf=GetSurface(l\mesh,1)
		
;		For i=0 To l\count-1
	
;			s.sprite = Object.sprite( PeekInt(l\spritebank,i*4) )


		For s.sprite=Each sprite
			TFormPoint s\x,s\y,s\z,0,camera
			
			If TFormedZ#()>0
					
				TFormVector -s\s,-s\s,0,camera,0 
				VertexCoords s\surf,s\verti[0],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#()
				
				TFormVector s\s,-s\s,0,camera,0 
				VertexCoords s\surf,s\verti[1],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#()

				TFormVector -s\s,s\s,0,camera,0 
				VertexCoords s\surf,s\verti[2],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#()
	
				TFormVector s\s,s\s,0,camera,0 
				VertexCoords s\surf,s\verti[3],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#()
			
			EndIf
		Next
			
;	Next
End Function

;--------------------------------------------------------------------------------------------

Function CreateLayer()
	l.layer=New layer	
	l\mesh=CreateMesh() : surf=CreateSurface(l\mesh)
;	l\spritebank=CreateBank()
	NameEntity l\mesh,Handle(l)
	EntityColor l\mesh,255,255,255
	EntityFX l\mesh,1+32
	EntityBlend l\mesh,3
	Return l\mesh
End Function

;--------------------------------------------------------------------------------------------

Function AddSprite(mesh)
	l.layer=Object.layer(EntityName(mesh))
	surf=GetSurface(l\mesh,1)
;	l\count=l\count+1
	;ResizeBank l\spritebank,l\count*4
	
	;create a new sprite
	s.sprite=New sprite
	
	s\verti[0]=AddVertex(surf,0,0,0,0,1) ;topleft
	s\verti[1]=AddVertex(surf,0,0,0,1,1) ;topright
	s\verti[2]=AddVertex(surf,0,0,0,0,0) ;bottomleft
	s\verti[3]=AddVertex(surf,0,0,0,1,0) ;bottomright
	
	AddTriangle(surf,s\verti[1],s\verti[2],s\verti[3])
	AddTriangle(surf,s\verti[2],s\verti[1],s\verti[0])
	s\s=10 : s\a=1
	s\r=255 : s\g=255 : s\b=255
	s\x=0 : s\y=0 : s\z=0
	s\surf=surf
	
	;put the new sprite into the bank
;PokeInt l\spritebank,(l\count*4)-4,Handle(s)
	Return Handle(s)
End Function
;--------------------------------------------------------------------------------------------

Function AlphaSprite(sprite,Alpha#)
	s.sprite = Object.sprite(sprite)
	
	VertexColor s\surf,s\verti[0],s\r,s\g,s\b,Alpha#
	VertexColor s\surf,s\verti[1],s\r,s\g,s\b,Alpha#
	VertexColor s\surf,s\verti[2],s\r,s\g,s\b,Alpha#
	VertexColor s\surf,s\verti[3],s\r,s\g,s\b,Alpha#
End Function

;--------------------------------------------------------------------------------------------
Function PositionSprite(sprite,x#,y#,z#)
	s.sprite = Object.sprite(sprite)
	s\x=x
	s\y=y
	s\z=z
End Function

;--------------------------------------------------------------------------------------------

Function fps()
	fpsindex=fpsindex+1
	fpstime=fpstime+MilliSecs()-fpsfold_millisecs
	If fpstime=>1000
		fpsfps=fpsindex
		fpstime=0
		fpsindex=0
	EndIf
	fpsfold_millisecs=MilliSecs()
	Return fpsfps
End Function

;--------------------------------------------------------------------------------------------

Function TransTex(texture,angle#,scale#=1)
	ScaleTexture texture,scale,scale
	RotateTexture texture,angle#
	x#=Cos(angle)/scale/2
	y#=Sin(angle)/scale/2
	PositionTexture texture,(x-.5)-y,(y-.5)+x
End Function



;--------------------------------------------
; M O U S E L O O K
;
; Parms: 
; Cam   - Camera
; T     - Current timer
; Time1 - Last time event ran
; Freq  - How often in milliseconds this function runs
Function Mouselook(Cam,T,Time1,Freq)

If T > Time1 + Freq Then
	Time1=T
	
	If MouseDown(2) Then 

		TurnEntity cam,MouseYSpeed(),-MouseXSpeed(),0
		RotateEntity cam,EntityPitch(cam), EntityYaw(cam),0
		MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

	EndIf
EndIf
Return Time1

End Function