TNT Basic Forums > Programming Q&A
< Last Thread     Next Thread >
Thread        Post A Reply

01-23-2002 17:52

Posted by:
Tony Rose

Find more posts by Tony Rose

Ok,heres the deal. My program was running at a rock solid 40 fps (maybe coulda went higher,havent tryed) but after adding a fairly small amount of code to my bullet system,my FPS is dropping to 30-36 fps,which makes the game seem sluggish. When firing bullets before it still remained a solid 40. Here is the code I added that has affected performance so much. If anyone can spot something that im doing horribly wrong let me know. Also,if you wanna take a look at the entire program so far I can send it to you via email (only 88k)

procedure bCol()
'Bullet Collision Detect
'First Bullet
bSwitch[0]=Sprite Col(3,4 to 1000)
if bSwitch[0]>-1
sprite off 3
end if
'Second Bullet
bSwitch[1]=Sprite Col(4,5 to 1000)
if bSwitch[1]>-1
sprite off 4
end if
'Third Bullet
bSwitch[2]=Sprite Col(5,6 to 1000)
if bSwitch[2]>-1
sprite off 5
end if
'Fourth Bullet
bSwitch[3]=Sprite Col(6,7 to 1000)
if bSwitch[3]>-1
sprite off 6
end if
'Fifth Bullet
bSwitch[4]=Sprite Col(7,8 to 1000)
if bSwitch[4]>-1
sprite off 7
end if
'Sixth Bullet
bSwitch[5]=Sprite Col(8,9 to 1000)
if bSwitch[5]>-1
sprite off 8
end if
'Seventh Bullet
bSwitch[6]=Sprite Col(9,10 to 1000)
if bSwitch[6]>-1
sprite off 9
end if
'Eighth Bullet
bSwitch[7]=Sprite Col(9,11 to 1000)
if bSwitch[7]>-1
sprite off 10
end if
'Ninth Bullet
bSwitch[8]=Sprite Col(10,12 to 1000)
if bSwitch[8]>-1
sprite off 11
end if
'Tenth Bullet
bSwitch[9]=Sprite Col(11,13 to 1000)
if bSwitch[9]>-1
sprite off 12
end if
'Eleventh Bullet
bSwitch[10]=Sprite Col(12,14 to 1000)
if bSwitch[10]>-1
sprite off 13
end if
'Twelth Bullet
bSwitch[11]=Sprite Col(13,15 to 1000)
if bSwitch[11]>-1
sprite off 14
end if
end proc

01-23-2002 23:37

Posted by:
Mark Tully

Find more posts by Mark Tully

Faster, faster....

Hi Tony,

You're not really doing anything wrong, it's really just what you're doing is taking TNT Basic a long time. You're asking it to check for collisions between 1 sprite and pretty much a thousand others, and then doing that 12 times, that means TB's trying to test 12,000 every frame, which is why it's struggling.

I'm assuming most of these sprites aren't actually on, so I might be able to optimise TNT Basic there. Could you email me your project and I'll have a ponder over making things faster in that area.

In the meanwhile, I'd recommend trying 2 things:

1) Lower the number of sprites it checks against if possible, (ie do you really need to check against a 1000 other sprites?)

2) Alternate your checking code, like check the even numbered bullets on one frame, then the odd numbered bullets on the next frame.
If that's not fast enough try checking 2 bullets per frame or something. This is probably alright because unless your bullets are moving very fast, their turn for collision detection will come up before they've moved through their target.

By implementing these, you will lower the number of collision tests per frame and speed up your game.

If you need any more help (because I'm not sure I explained this well!) - just post.



01-24-2002 03:11

Posted by:
Tony Rose

Find more posts by Tony Rose


Hehe..ok that was a mistake on my part. I set it to check through 1000 just so I wouldnt ever have to go back and raise those numbers as I added sprites to my game. I didnt realise it would check over the sprites that werent there..doh! Hehe,guess I just cant be so lazy! And btw,thanks for responding so fast to all my questions!

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.