I wrote this function for my own games but just wanted to share it here where it might be of any interest.
Functions:
QueueSprite()
QueueSync()
QueueRadix()
Usage:
Do
QueueSprite(Image,x,y,Alpha,Mirror)
QueueSync()
Sync
cls
loop
Example:
gosub Initialize
do
gosub QueueStuff
ink 0,0
text 0,0,str$(screen fps())
QueueSync()
sync
cls rgb(255,255,255)
loop
QueueStuff:
`Queue Object array in a loop
for lp = 4 to MAX
QueueSprite(ObjectImage(lp),ObjectX(lp),ObjectY(lp),ObjectAlpha(lp),ObjectMirror(lp))
next lp
`Queue Object array manually
QueueSprite(ObjectImage(1),ObjectX(25),ObjectY(25),255,0)
`Queue with hard values
QueueSprite(PointerTiles+2,320,250,255,0)
`Queue with mouse coordinates
mx = mouseX()-16
my = mouseY()-16
QueueSprite(PointerTiles+0,mx,my,255,0)
`Queue a transparent Tile
QueueSprite(PointerTiles+3,100,100,125,0)
return
Initialize:
set display mode 640,480,32
sync on
sync rate 0
`Objects Array
MAX = 50
global dim ObjectImage(MAX)
global dim ObjectX(MAX)
global dim ObjectY(MAX)
global dim ObjectAlpha(MAX)
global dim ObjectMirror(MAX)
`Create Tiles
#constant PointerTiles 100
for lp = 0 to MAX
ink rgb(10,10,10),0
box 0,0,32,32
ink rgb(255-rnd(100),255-rnd(100),255-rnd(100)),0
box 1,1,31,31
ink 0,0
center text 16,8,str$(lp)
get image PointerTiles+lp,0,0,32,32
ObjectImage(lp) = PointerTiles+lp
ObjectX(lp) = 16+rnd(592)
ObjectY(lp) = rnd(448)
ObjectAlpha(lp) = 255
ObjectMirror(lp) = 0
next lp
`Queue Function
q = 1000
global dim QueueImage(q)
global dim QueueX(q)
global dim QueueY(q)
global dim QueueSort(q)
global dim QueueAlpha(q)
global dim QueueMirror(q)
global QueueCount = -1
`Radix Function
global dim Radix(15,q)
global dim RadixCount(15)
global dim Priority(q)
return
`//////////////////////////////////////////////////////////////////////////
`// Functions
`//////////////////////////////////////////////////////////////////////////
Function QueueSprite(i,x,y,a,m)
inc QueueCount
QueueImage(QueueCount) = i
QueueX(QueueCount) = x
QueueY(QueueCount) = y
QueueSort(QueueCount) = y+100
QueueAlpha(QueueCount) = a
QueueMirror(QueueCount) = m
EndFunction
Function QueueSync()
QueueRadix()
for lp = 0 to QueueCount
p = Priority(lp)
sprite 1,640,0,QueueImage(p)
if QueueMirror(p)
if sprite mirrored(1) = 0 then mirror sprite 1
else
if sprite mirrored(1) then mirror sprite 1
endif
set sprite alpha 1,QueueAlpha(p)
paste sprite 1,QueueX(p),QueueY(p)
next lp
QueueCount = -1
EndFunction
Function QueueRadix()
for lp = 0 to QueueCount
Priority(lp) = lp
next lp
a = 15
b = 1
for r = 0 to 2
for lp = 0 to QueueCount
d = (QueueSort(Priority(lp)) && a) / b
Radix(d,RadixCount(d)) = Priority(lp)
inc RadixCount(d)
next lp
p = 0
for lp = 0 to 15
x = RadixCount(lp)-1
for lpx = 0 to x
Priority(p) = Radix(lp,lpx)
inc p
next lpx
RadixCount(lp) = 0
next lp
b = b*16
a = b*16-1
next r
EndFunction