|  | 
 
 5- Use Rect instead of Line :Believe it or not Rect is much much faster at drawing Horizontal and vertical lines than Line command itself.6- Do not use GetColor :Using Getcolor inside game loop will slow it down, instead try using ReadPixel , though you will need to calculate the color manually.7- No need for CLS :If you are going to DrawBlock/TileBlock the background then no need to use CLS; it is useless in this situation.8- Pre-calculate :Well, if you are going to rotate or resize an image then it is much faster to do that outside the main game loop and save the rotated/resized images in an ,say, array and then use this array handle inside the game loop. The same applies for pre-calculating Cos/Sin values to make attack waves in your game, as this will slow the game down if you calculate it in real time.9- Save your self some Function calls :If you are going to use a Blitz intrinsic function like ImageHeight() and ImageWidth()...etc in loops then it is better to assign it to a variable and then use the variable in your loops instead, well look at this :The following code is faster: 10- Divide your formulas :In my game Pharaohs' Curse I am using the following code to get the current tile where the player is located :The following code is faster (especially when you have many variables which stores the tile located to the left, right, up, down , top-middle, bottom-middle....etc of the player) 11- Un-necessary Math Functions :Well, look at thisthat is faster: 12- Change between 0 and 1 :If a variable is going to be changed between 0 and one then you better use :instead of Same applies to Boolean variable as you can use: bVariable= Not bVariable 13- Counting :If you have a variable which needs to be iterated from 1 to ,say, 20 then it is better to use :instead of 14- Loop Step :If you have a loop like the following :Try use the following 15- Use conditions wisely :Try the following, it is faster : 16- Join conditions :From the previous example, the following is faster17- Un-necessary If statements :Look at this :It is better and faster to use : 18- Select Insted of Ifs :Try using Select instead of Ifs as it is better, faster and more readableInstead 19- Gosub instead of Functions :Using Gosub is faster than using Functions even though I sacrifice speed for more readable code as Function make it easy to read your code.20- Do not use Goto :As much as you can try avoid using Goto it is notoriously known of causing bugs and unstructured code (Pascal programmers, are you there?!!).Lastly :Well, I hope this help you gain some tricks to make your game runs much faster, till we meet again with the next article where I will explain how to write your real time REPLAY feature for you game, I have implemented this cool feature in my game Pharaohs' Curse which helps you see the computer solve a given level/stage for you.
 Well, Bye for now. Maher Farag 
 For a printable copy of this article, please click HERE. 
 This site is CopyrightŠ 2000-2004, BlitzCoder. All rights reserved.   |