Drawing Images

Hi everyone

I’m building a 2D game using openframeworks and I’ve been making some experiments with box2d and the framework to build the mechanics the game will have.
Now I’m working on getting the images and sprites drawn on screen, and I had some odd behaviour.
The game is a tiled based game, so, each tile (64x64 pixels) will have an image.
The thing is that, when I draw the images of each tile (inside the draw method) the performance gets REALLY slow.

Each image is an ofImage object and I use its draw method.
Is there a better way to do this? What am I doing wrong?

You probably want to use fewer actual textures and assign each of your tiles a rect out of one of the textures that you’ve loaded up. So each tile will have an ofRectangle and a pointer to the ofTexture that contains its sprite and will use ofTexture.drawSubsection(). That should speed things up a lot. You can also check out https://github.com/stfj/ofxSpriteSheetRenderer for a more structured way of doing that. Hope that helps,

I’ve tried to work with ofFbo, drawing to a ofFbo and later drawing it. It worked, my frame rate stays about 58.
What is the “right way” to do it?

I’m kind of confused about it.

That sounds like one of the right ways to do it. Anything that reduces the number of textures that you’re using and the number of actual textures that you’re drawing is the right way :slight_smile: