My game is too slow!
BlitzPlus Forums/BlitzPlus Programming/My game is too slow!
| ||
I'm making an editor where you lay tiles down and create your own platform game. You can also put enemies on the map. The problem is, when you place too many blocks or enemies the game slows down ALOT.(I think it is because each enemy has to check collision with each block) Does anybody know any ways to speed this up? P.S. Also, does anyone know how to check the frame rate of your program? thnx |
| ||
1) anything should only check collision on things in its adjacent area not everything on the map, even 3d games dont check everything just the things they are near that need checking. 2) Store the current time (using CurrentTime$() ), update a frame counter every frame when the stored time is different from CurrentTime$() then store the value for displaying and reset the other value the stored value will be the FPS. Also set the stored time to CurrentTime$() this will allow for a constant FPS update every second. |
| ||
Um, could i have an example please? I don't know how to do either of those. |
| ||
It's dangerous to go alone! Take this!; Graphics ; Graphics 640, 480, 0, 2 SetBuffer BackBuffer( ) ; Tilemap ; Dim tilemap( 9, 9 ) tileSize = 32 ; Main program ; Repeat ; Get mouse tile position ; mouseTileX = MouseX( ) / tileSize mouseTileY = MouseY( ) / tileSize ; Draw tilemap ; For y = 0 To 9 For x = 0 To 9 If mouseTileX = x And mouseTileY = y Then Color 255, 0, 0 Else Color 0, 128, 255 EndIf Rect x * tileSize, y * tileSize, tileSize + 1, tileSize + 1, 0 Next Next ; Program end ; Flip Cls Until KeyHit( 1 ) ; Truly end ; End Basicly, the mouse position is the players position. Now you know where the player is on the tilemap so you can make a smaller loop for collision checking: ; Player collision check ; For x = mouseTileX - 1 To mouseTileX + 1 For y = mouseTileY - 1 To mouseTileY + 1 ; Collision code Next Next |
| ||
Can anyone explain the frame rate thing better please? |
| ||
Yep, if you find how long a frame took, and then 1000/HowLong, this gives you the Frame rate per second. |
| ||
...and how do i find the "How Long"? |
| ||
Seriously, don't whine "how" all the time and do some research/math yourself. There is a nice code archive on this site where you can find lots of usefull stuff you know. |
| ||
You find the time now, then find the time after a frame. |