10k Sprites
Try this code I robbed from Rob.
Replace fire1.png with your own png.
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 ("fire.png",2+48)
test=CreateLayer()
EntityTexture test,fire
For i=0 To 10000
temp = AddSprite(test)
PositionSprite temp,Rnd(-500,500),Rnd(-500,500),Rnd(-500,500)
Next
;--------------------------------------------------------------------------------------------
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)
; 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
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 DeleteSprite(mesh,sprite)
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