Following on from Sterling's tip on freeing up images, I have this to ask.
I adapted the bouncing ball code from 'Krylar's book and had 100 balls bouncing around the screen. These balls were all grabbed from a simple oval drawn at the beginning of the program.
I decided I wanted 100 different coloured balls bouncing around the screen, so I did away with the grabimage and drew each one out in the main game loop.
Now, my question is - which is better?
Without grabbing the image, do I still need to free up graphic memory, or does it not apply here as I'm drawing each one out in turn?
Here's the code:
Graphics 1024,768,32,1
SetBuffer BackBuffer()
SeedRnd MilliSecs()
HidePointer
MX =MouseX()
MY =MouseY()
Type blobz
Field x
Field y
Field xx
Field yy
Field c1
Field c2
Field c3
End Type
For f=0 To 100
b.blobz = New blobz
b\x = Rnd(970)
b\y = Rnd(730)
b\xx = Int(Rnd(2)+1)
b\yy = Int(Rnd(2)+1)
b\c1 = Int(Rnd(1,255))
b\c2 = Int(Rnd(1,255))
b\c3 = Int(Rnd(1,255))
Next
While KeyDown(1) = False
Cls
For b.blobz = Each blobz
If b\x>980 Then b\xx=-Int(Rnd(2)+1)
If b\x<0 Then b\xx=Int(Rnd(2)+1)
If b\y>730 Then b\yy=-Int(Rnd(2)+1)
If b\y<0 Then b\yy=Int(Rnd(2)+1)
Color b\c1,b\c2,b\c3
Oval b\x,b\y,30,30
Color 255,255,255
Oval b\x+5,b\y+5,5,5
b\x=b\x+b\xx
b\y=b\y+b\yy
If mx<>MouseX() Then End
If my<>MouseY() Then End
Next
Flip
Wend
End
I adapted the bouncing ball code from 'Krylar's book and had 100 balls bouncing around the screen. These balls were all grabbed from a simple oval drawn at the beginning of the program.
I decided I wanted 100 different coloured balls bouncing around the screen, so I did away with the grabimage and drew each one out in the main game loop.
Now, my question is - which is better?
Without grabbing the image, do I still need to free up graphic memory, or does it not apply here as I'm drawing each one out in turn?
Here's the code:
Graphics 1024,768,32,1
SetBuffer BackBuffer()
SeedRnd MilliSecs()
HidePointer
MX =MouseX()
MY =MouseY()
Type blobz
Field x
Field y
Field xx
Field yy
Field c1
Field c2
Field c3
End Type
For f=0 To 100
b.blobz = New blobz
b\x = Rnd(970)
b\y = Rnd(730)
b\xx = Int(Rnd(2)+1)
b\yy = Int(Rnd(2)+1)
b\c1 = Int(Rnd(1,255))
b\c2 = Int(Rnd(1,255))
b\c3 = Int(Rnd(1,255))
Next
While KeyDown(1) = False
Cls
For b.blobz = Each blobz
If b\x>980 Then b\xx=-Int(Rnd(2)+1)
If b\x<0 Then b\xx=Int(Rnd(2)+1)
If b\y>730 Then b\yy=-Int(Rnd(2)+1)
If b\y<0 Then b\yy=Int(Rnd(2)+1)
Color b\c1,b\c2,b\c3
Oval b\x,b\y,30,30
Color 255,255,255
Oval b\x+5,b\y+5,5,5
b\x=b\x+b\xx
b\y=b\y+b\yy
If mx<>MouseX() Then End
If my<>MouseY() Then End
Next
Flip
Wend
End