my programs very slow
BlitzPlus Forums/BlitzPlus Programming/my programs very slow
| ||
I am new and my programs run very slow , I have a fast computer , any tips to incrase the speed of my games?? thx |
| ||
Are you using the "text" command? On certain video cards with certain driver versions, that command is the death of performance. |
| ||
I think you will need to specify a little more about your program before anyone can really help you. Is it 2d or 3d? Guessing 2d since this is in blitzplus. What resolution are you running at? How many graphics are you loading? If you are drawing tiles, How many? Are you running with debug on? If 3D, how many polys? How many entities?,... |
| ||
I think you might be doing something like loading an image inside a loop. Can you post your code? or your loop? |
| ||
Graphics 200,400 Const UPKEY = 200,LEFTKEY = 203, RIGHTKEY = 205, DOWNKEY = 207 , SPACEBAR = 57 Const ship1$ = "<>" Const bullet1$ = "." Const enemy1$ = "<><>" Type ship Field x,y End Type Type bullets Field x,y End Type Type enemys Field x,y Field movx,movy End Type Global player.ship = New ship Global enemy.enemys = New enemys While Not KeyDown(1) SetBuffer BackBuffer() Cls If KeyHit(LEFTKEY) player\x = player\x - 3 EndIf If KeyHit(RIGHTKEY) player\x = player\x + 3 EndIf If KeyHit(UPKEY) player\y = player\y - 3 EndIf If KeyHit(DOWNKEY) player\y = player\y + 3 EndIf If KeyHit(SPACEBAR) bullet.bullets = New bullets bullet\x = player\x bullet\y = player\y EndIf drawship() testbullets() drawenemy() Flip Wend Function drawship() Text player\x,player\y,ship1$ If player\x < 2 player\x = 5 EndIf If player\x > 193 player\x = 190 EndIf If player\y < 0 player\y = 5 EndIf If player\y > 390 player\y = 389 EndIf End Function Function testbullets() For bullet.bullets = Each bullets bullet\y = bullet\y - 5 If bullet\y < 0 Delete bullet Else Text bullet\x,bullet\y,bullet1$ EndIf Next End Function Function drawenemy() enemy\x = 100 enemy\y = 100 enemy\movx = Rnd(-3,3) enemy\movy = Rnd(-3,3) enemy\x = enemy\x + enemy\movx If enemy\x < 0 Or enemy\x > 200 enemy\movx = -enemy\movx EndIf Text enemy\x,enemy\y,enemy1$ End Function well thats my code, remember im a newb , and any tips and stuff I appreciate them . Also any tips to improve I appreciate 'em also. |
| ||
You don't need to "SetBuffer" every frame. Just once at the start is fine since you aren't changing it... And I see that you ARE using the text command. If you remove those, does the program speed up? |
| ||
He must also have debug on because I don't know of any gfx cards that will boot into a fullscreen mode of 200x400 =] I'd be willing to bet quite a bit that it's the Text command that's screwing things up. SetBuffer doesn't slow things down, although it is unneccessary to have it in the main loop. Problem for him though Epic, is that it's a text game. =] What you're gunna need to do, ngi, is use graphics in place of the text. The plus side to that is, you're not limited to the ASCII charset =] |
| ||
Okay I will try to do a game with graphics and see if it is faster. thx =) |
| ||
This runs real fast for me...even with text. Keep in mind people, just because there is a few text commands doesn't mean the program will slow to a crawl...text is ok for small things like what he is doing. Also, you had the wrong scancode for the down arrow. Const scr_w = 640 Const scr_h = 480 Graphics scr_w, scr_h,32,1 SetBuffer BackBuffer() Const UPKEY = 200,LEFTKEY = 203, RIGHTKEY = 205, DOWNKEY = 208 , SPACEBAR = 57 Const ship1$ = "<V>" Const bullet1$ = " ." Const enemy1$ = "<><>" Type ship Field x,y End Type Type bullets Field x,y End Type Type enemys Field x,y Field movx,movy End Type Global player.ship = New ship Global enemy.enemys = New enemys enemy\x=100 enemy\y=Rnd(200,400) While Not KeyDown(1) Cls If KeyDown(LEFTKEY) player\x = player\x - 3 EndIf If KeyDown(RIGHTKEY) player\x = player\x + 3 EndIf If KeyDown(UPKEY) player\y = player\y - 3 EndIf If KeyDown(DOWNKEY) player\y = player\y + 3 EndIf If KeyHit(SPACEBAR) bullet.bullets = New bullets bullet\x = player\x bullet\y = player\y EndIf drawship() testbullets() drawenemy() Flip Wend Function drawship() Color 0,255,0 Text player\x,player\y,ship1$ If player\x < 0 player\x = 0 EndIf If player\x > scr_w player\x = scr_w EndIf If player\y < 0 player\y = 0 EndIf If player\y > scr_h player\y = scr_h EndIf End Function Function testbullets() For bullet.bullets = Each bullets bullet\y = bullet\y + 5 If bullet\y > scr_h Delete bullet Else Color 255,255,255 Text bullet\x,bullet\y,bullet1$ EndIf Next End Function Function drawenemy() enemy\movx = Rnd(-3,3) enemy\movy = Rnd(-3,3) enemy\x = enemy\x + enemy\movx If enemy\x < 0 Or enemy\x > scr_w enemy\movx = -enemy\movx EndIf Color 255,255,0 Text enemy\x,enemy\y,enemy1$ End Function -cbmeeks |
| ||
great! that one works perfect thx man |
| ||
So what were the differances meeks? |
| ||
Well, first of all, he had the wrong scancode for the DownArrow. That may have botched some stuff up. I also changed KeyHits to KeyDowns (except for fire). Plus, full screen with larger area and I changed some colors for a neater look. Oh, and like everyone else said, took the SetBuffer BackBuffer() out of the main loop. cb |