1000 Sprites Demo

BlitzPlus Forums/BlitzPlus Programming/1000 Sprites Demo

Kevin_(Posted 2004) [#1]
Did some external commands to help AMAL development which works pretty well. I get 60 FPS on my XP24000 & ATI 9000 Pro. Think I'll start a work log soon. This should run in Blitz3D as well.


[Code]
; 1000 Sprites demo by Prof
;
; Some leaf functions to help with AMAL development.
;

Graphics 640,480,32,2
SetBuffer BackBuffer()
SeedRnd(MilliSecs())

Global Max_Sprites=1000

Dim Image_Bank(256)
Dim Sprite_Reg(Max_Sprites,3)

Color 50,50,100:Oval 0,0,31,31,True ; Creates a ball image
Color 50,50,150:Oval 2,2,24,24,True
Color 50,50,200:Oval 4,4,17,17,True
Color 50,50,250:Oval 6,6,10,10,True

Grab_Sprite_Image(1,0,0,32,32) ; Grab it to the image bank

Cls

For L=1 To Max_Sprites ; Place sprites on screen in random locations
Sprite(L,Rand(-32,640),Rand(1,480),1)
Next

Color 250,250,250

Repeat

For L=1 To Max_Sprites
X=Peek_X_Sprite(L) ; Get the x value of sprite

If L<=250 Then Speed=1
If L>250 And L<=500 Then Speed=2
If L>500 And L<=750 Then Speed=3
If L>750 Then Speed=4
NewX=X+Speed ; Calc a new X value
If NewX>640
NewX=-32
EndIf

Poke_X_Sprite(L,NewX) ; Poke a new X value into each sprite
Next

Sprite_Update(1,Max_Sprites) ; Draw all sprites to the screen

curTime = MilliSecs() ; FPS Code by Surreal - Thanks!
If curTime > checkTime Then
checkTime = curTime + 1000
curFPS = fpscounter
fpscounter = 0
Else
fpscounter = fpscounter + 1
End If
Text 220,230,"1000 Sprites Demo - "+Str(curFPS)+" FPS"

Flip
Cls

Until KeyHit(1)
End

; ****************************************************

Function Poke_Y_Sprite(Sp,v)
Sprite_Reg(Sp,2)=v
End Function

; ****************************************************

Function Poke_X_Sprite(Sp,v)
Sprite_Reg(Sp,1)=v
End Function

; ****************************************************

Function Peek_Y_Sprite(Sp)
; Returns a Sprite's Y Coordinate
Y=Sprite_Reg(Sp,2)
Return Y
End Function

; ****************************************************

Function Peek_X_Sprite(Sp)
; Returns a Sprite's X Coordinate
X=Sprite_Reg(Sp,1)
Return X
End Function

; ****************************************************

Function Sprite_Update(S,E)
For Sp=S To E
DrawImage Sprite_Reg(Sp,3),Sprite_Reg(Sp,1),Sprite_Reg(Sp,2)
Next
End Function

; ****************************************************

Function Grab_Sprite_Image(ImageID,x,y,w,h)
Image_Bank(IMageID)=CreateImage(w,h)
GrabImage Image_Bank(ImageID),x,y
End Function

; ****************************************************

Function Sprite(N,X,Y,ImageID)
Sprite_Reg(N,1)=X
Sprite_Reg(N,2)=Y
Sprite_Reg(N,3)=Image_Bank(ImageID)
End Function

; ****************************************************

[/Code]


Kevin_(Posted 2004) [#2]
Now managed to get 1000 'Alpha' sprites working with no slowdown :)


Grey Alien(Posted 2004) [#3]
My P4 3.2GHz with Radeon 9800XT gives 75 FPS due to the refresh rate of my card/monitor. Changing your Flip line to Flip (false) to disable VWait gives about 120FPS with Debug off.


Kevin_(Posted 2004) [#4]
Oooops! Yes you are quite right. I should have changed that.


Regular K(Posted 2004) [#5]
AMD Athlon 1.5, GeForce3 Ti 500
60 FPS
(using B3D demo)