Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've noticed in my small game that I get very low fps very quickly when multiple objects are on the screen.

The two objects that hogs performance are enemies and shots fired by either the player or the enemy.

After looping through a vector and moving all enemies I loop the vector again and renders each enemy.

C#
void renderEnemy(){
for (int i = 0;i<enemyVector.size();i++){
enemyVector[i].drawEnemy();
}
};


MIDL
void enemy::drawEnemy(){
const string playerFilename       = "SmallMine.tif";
const int    DROPS_X_FRAME_COUNT = 1;
const int    DROPS_Y_FRAME_COUNT = 1;
VGCImage     player               = VGCDisplay::openImage(
    playerFilename,
    DROPS_X_FRAME_COUNT,
    DROPS_Y_FRAME_COUNT
);
const VGCVector     frameIndex = VGCVector(0, 0);
const VGCVector     position   = VGCVector(xPos, yPos);
const VGCAdjustment adjustment = VGCAdjustment(0.0, 0.0);
VGCDisplay::renderImage(player, frameIndex, position, adjustment);
VGCDisplay::closeImage(player);


};

As you can see drawEnemy gets called quite a lot which slows down my game but I'm not sure on how to avoid this function getting called so many times.
Posted

1 solution

The problem is not that you are calling this function very often but rather that each time you are loading the file again and again. Reading a file from disk is a very slow operation and should be performed only once: you should load your file at the beginning of your program (or when your level is loaded) and keep in memory.

Which library are you using ? It's not DirectX nor OpenGL.
 
Share this answer
 
Comments
Dalek Dave 22-Oct-10 3:37am    
Good Call!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900