Which method is better?

Blitz3D Forums/Blitz3D Beginners Area/Which method is better?

Tobo(Posted 2005) [#1]
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


Tobo(Posted 2005) [#2]
Actually........ do I need to free up my types when exiting the program?


Beaker(Posted 2005) [#3]
The code example above doesn't particularly use any graphics memory (apart from the standard buffers), because you don't load or create any images. So you don't need to free any images.

Having said that, you will get faster code if you create a small number of images of the colors used (blue, red, green, orange etc) and then select them at random.

Also, Blitz will clear up everything when it exits.

You can simplify your code (and probably make it a little faster) by using Rand() in place of Int(Rnd()), as it equates to the same thing.


Tobo(Posted 2005) [#4]
> Rand()

Well I never!

God bless these forums.

Thanks,

Tobo.