chimpoid
Member
Hi all,
I'm plowing on with my first game/c++ project and have noticed that since switching from using bitmaps with a colorkey to alpha keyed .png files there has been a small dent made in performance.
To cover the basic layout of the current rendering stuff. It's a bit like this....
Rendering out each surface one at a time and then an SDL_Flip.
The backdrop, 3 penguins, layer 1, 3 penguins, layer 2, 3 penguins, layer 4. Flip.
Sooooo, all the surfaces except the backdrop rely on alpha transparency.
All layers are rendered each frame
I had looked at running a switch statement to only render the current "live" penguin. Each penguin is numbered and there is an int declared "pengInPlay". Each penguin has its own surface "p" followed by its number. So penguin one is on a surface called "p1" , penguin 2 is on a surface "p2", and so on.
This lets me render the layers in the correct order drawlayer("Backdrop"), drawlayer("p1").... in order to slot the penguins between the layers.
The problem I was getting was trying to use the int pengInPlay to construct a call to the corret surface. I tried sprintf to convert the int to a string and then concat after "p" to give the surface name but that fell apart. (thinking in php) So I am left with the option of running multiple if statements like so.
The other thought I had was to make 1 surface for 1 penguin. Then use a switch statment in the rendering section. In pseudo code.
Does anyone have any suggestions as to the best route to take. I think that the second would be the fastest but I am keen to hear how others would approach the problem of ordering the sequence of surfaces to be blitted.
I'll update the game on the site in a few minutes and pop the source code there as well.(don't laugh )
Updated game and source are here - Latest Version
Thanks
Chimpoid.
I'm plowing on with my first game/c++ project and have noticed that since switching from using bitmaps with a colorkey to alpha keyed .png files there has been a small dent made in performance.
To cover the basic layout of the current rendering stuff. It's a bit like this....
Rendering out each surface one at a time and then an SDL_Flip.
The backdrop, 3 penguins, layer 1, 3 penguins, layer 2, 3 penguins, layer 4. Flip.
Sooooo, all the surfaces except the backdrop rely on alpha transparency.
All layers are rendered each frame
I had looked at running a switch statement to only render the current "live" penguin. Each penguin is numbered and there is an int declared "pengInPlay". Each penguin has its own surface "p" followed by its number. So penguin one is on a surface called "p1" , penguin 2 is on a surface "p2", and so on.
This lets me render the layers in the correct order drawlayer("Backdrop"), drawlayer("p1").... in order to slot the penguins between the layers.
The problem I was getting was trying to use the int pengInPlay to construct a call to the corret surface. I tried sprintf to convert the int to a string and then concat after "p" to give the surface name but that fell apart. (thinking in php) So I am left with the option of running multiple if statements like so.
Code:
if (pengInPlay ==1){
drawlayer("p1");
}
//repeat for all penguins.
The other thought I had was to make 1 surface for 1 penguin. Then use a switch statment in the rendering section. In pseudo code.
Code:
case (current penguin is between 1 & 3):
draw the penguin layer 2nd;
break;
case (current penguin is between 4 & 6):
draw the penguin layer 3rd;
break:
etc.etc.
Does anyone have any suggestions as to the best route to take. I think that the second would be the fastest but I am keen to hear how others would approach the problem of ordering the sequence of surfaces to be blitted.
I'll update the game on the site in a few minutes and pop the source code there as well.(don't laugh )
Updated game and source are here - Latest Version
Thanks
Chimpoid.