|
|
| Very slow while drawing to screen |
|
Quintinon
Member #8,554
April 2007
|
I'm having a weird problem I know I shouldn't be running into with my program ... but I have basically a game engine that displays a character and a screen full of 32x32 tiles of 'grass'.(These are place holder graphics for the real game ... no point in getting a bunch done when the engine doesn't even work) I can draw the character and move him around fine, but when I start drawing the tiles(even just one row slows it down considerably) it gets HORRIBLE ... I don't understand what could be going wrong here and would like some help. Main program cpp file.
Header file for MapEngine. #ifndef MapEngine_h_included #define MapEngine_h_included int loadMap(std::string s); int loadTiles(void); BITMAP* drawMap(int x, int y, int a, int b); #endif Cpp file for MapEngine
and for the map file right now I'm using 50x50 of grass, which it should only be displaying around half of that I think. |
|
Trent Gamblin
Member #261
April 2000
|
Quote:
Tile = load_bitmap(getTile(map[x][y]).c_str(), desktop_palette); What you should be doing here is drawing tiles from a pre-loaded array (or perhaps a vector if you're using C++) or tilemap. Loading from disk is much slower than loading from memory. So you need a function to load all the tiles into memory at the start of your game or level, storing them in a global array or vector. Then draw them directly. [edit] Don't forget to destroy the bitmaps where you're done with them. The code you have now will cause your computer to run out of memory in a hurry. If eating hotdogs is wrong, I don't wanna be right. |
|
HardTranceFan
Member #7,317
June 2006
|
because you have Tile = load_bitmap(getTile(map[x][y]).c_str(), desktop_palette); in MapEngine.drawMap Load the image once in MapEngine.loadMap [edit] -- |
|
Peter Wang
Member #23
April 2000
|
Note also that desktop_palette is considered read-only. Don't pass it to load_bitmap. Supply your own PALETTE structure to receive the palette.
|
|
gnolam
Member #2,030
March 2002
|
And don't copy your buffer to the screen with draw_sprite() - use blit(). -- |
|
|