I’m student and i try to do a game in 2D for my project in first year. I’m too beginner in C ++.
I’m trying to do this game with openframework and i have FPS problem for the map display.
// 32 pixel * 32 pixel = image size.
nbrCaseX = ofGetScreenWidth() / 32;
nbrCaseY = ofGetScreenHeight() / 32;
for (int x = 0; x < nbrCaseX; x++) {
for (int y = 0; y < nbrCaseY; y++) {
sprite.drawSubsection(x*32, y*32, 32, 32, 608, 0, 32, 32);
}
}
But with this draw, FPS is now 10-15 fps maximum.
How can I optimize the code for a lot of sprite display ?
Asuming the sprites are not going to change dynamically, instead of drawing multiple times every frame the small sprites, you could pregenerate the large sprite by combining the small sprites, and just draw that one once every frame.
Ok. But how can i generate this sprite ? Which function can do that ?
I have found on the forum that some people work with pixel. Must i work with pixel or can I work with small image ?
You could also use ofxSpriteSheetRenderer to batch render a lot of sprites. It may be a little bit more complex if you are new to c++, but well worth it if you want to have a lot of particles etc.
I test on my monitor ( 1920 *1080 ). Thus i have 60 image in width and 40 image in height, I must display 2400 small image on my screen. And this each frame. It’s not good and useless because this background map is always the same. Build an image is a good idea. And i can refresh it each time i need.
I can test, but i think that the solve of Hennio is better.