[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Re: Tile scrolling game



I'm currently attempting to write a top down scrolling RPG type game in Pygame, using tiles.

Of course, problems arise with large maps filled with tiles, as the frame rate plummets. I'd like the game to be set on a single island, meaning that the amount of tiles in memory at once is currently huge (for the moment I'm working with 50*50, since that leaves me with a workable framerate of 17). The framerate needn't be too perfect, but obviously it'd be nicer to make it smoother and have bigger islands.

Basically, two questions:
1) What is it that slows down the redraw - attemping 2500 blits per cycle, or attemping 2500 * 40 * 40 (sprites) per cycle? In other words - could I create a bigger (more tiles) island by decreasing the tile size?
2) How easy would it be to implement a system where it only keeps tiles in memory which are, say, within 20 tiles distance from the player?
Alex, the Sprite system won't be that efficient for a tiled background. A tiled background is a more defined set of data that can be more efficiently handled.

Just so you know, when SDL does a blit to a position outside the destination image, it does not actual blitting. Still, rectangle bounds much be checked and doing that a significan number of times will begin to be visible.

If you are doing a vertical scroller, it shouldn't be difficult to isolate the map into smaller sections. The map can likely only scroll in one direction, so once something passes off the bottom it can be discarded. Plus, given the position of the player it should be simple to know which tiles will be visible, and only deal with rendering those.

Fullscreen scrolling is possible with SDL and pygame, and should be able to run at higher framerates than you are seeing. Still, it takes a bit of care to make sure Python doesn't get in the way of these sorts of things, performance wise.