SFML community forums
Help => Graphics => Topic started by: joaosausen on May 11, 2012, 11:28:08 pm
-
So, i created pacman in a way where I print a map that i read from a txt file, I'm using tiles to build the map, then I do a CopyScreen to render all the map in only one image. My problem is what I do about the food, there is a way to modify a image without printing? If I can do that, i will just print a floor tile over the food tile.
Or there is a better way to handle this?
-
First, don't use copy screen. It is a very expensive operation. As for drawing your map, draw whatever doesn't change like the map walls and background to a RenderTexture. Then draw the RenderTexture every frame.
As for food, simple loop through an array of food where it is spawned and redraw a sprite for every location every frame.
-
RenderTexture, hmm
I will take a look at this, this is what Im doing in some way..
Anyway, im trying to not use loops inside the main while to print images, anyway, thanks for the help
-
Anyway, im trying to not use loops inside the main while to print images, anyway, thanks for the help
Well, loops is how programs work, so deciding not to use them it not going to help you ;)
If you don't want to clutter up the main with a lot of code then split your code up into classes. Throwing everything together in one subroutine or function is not the best of ideas anyways.
-
RenderTexture, hmm
I will take a look at this, this is what Im doing in some way..
Why do you need an off-screen image/texture?
Okay it makes sense for the map but the rest, just draw it to the screen.
For example:
- Application start
- Load map from file
- Render map to RenderTexture and extract texture
- for each frame: draw map texture, fruits and monsters