Im having trouble with the single surface sprite system!

as you can see in this example! the sprites appear to be in the wrong order!
HELP ME!!! PLEASE!
this is driving me up the wall :(
Thanks guys

as you can see in this example! the sprites appear to be in the wrong order!
Global fpsindex#,fpstime#,fpsfold_millisecs#,fpsfps#,time,xyzturn Type layer Field mesh Field count Field spritebank ; pointer to a type just for holding a list of sprites 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) Global 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 ;-------------------------------------------------------------------------------------------- HidePointer While Not KeyHit(1) MoveEntity camera,0,0,MouseZSpeed()*10 mxspd#=MouseXSpeed()*.2 myspd#=MouseYSpeed()*.2 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 TurnEntity camera,myspd,-mxspd,0 TransTex(fire,MilliSecs()*0.08) ;virtexnormals UpdateSprites() UpdateWorld RenderWorld Text 0,0,fps() Flip 0 Wend End ;-------------------------------------------------------------------------------------------- Function UpdateSprites() 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#() VertexNormal 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#() VertexNormal 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#() VertexNormal 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#() VertexNormal s\surf,s\verti[3],s\x+TFormedX#(),s\y+TFormedY#(),s\z+TFormedZ#() EndIf Next UpdateNormals test 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,1 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 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 ;-------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------
HELP ME!!! PLEASE!
this is driving me up the wall :(
Thanks guys