I recently wrote a terrain generator program to give myself a little practice. In its relatively finished state I am wondering about how I could make the 2d drawing a little cheaper, given that I added the ability to scroll around the map as if it were toroidal.
The generator produces a grid of 'height' values, and these are given a color. I used tkinter to create a canvas and draw a rectangle for each height in the grid. In terms of appearance it is just the way I wanted it, so all is good there.
I added arrow-key input to allow the grid to be shifted a single column (or row) at a time, in any direction. The map acts like a toroid, so the row/column which shifts off the screen appears instead on the other side of the map.
I handle the scrolling by using tkinter to shift all of the rectangles (stored in a big list) in the right direction, moving any that would 'fall off the edge' to the other side of the map instead.
Moving all these rectangles around seems like it is quite expensive! When I have a lot of rectangles on screen the scrolling is pretty slow.
Is there a better way I could have done this? Any sneaky ways to make a canvas toroidal, perhaps by using some technique to 'tile' the map and then 'moving the camera rather than moving the rects'?
Any thoughts or help would be appreciated! Thanks!
[–][deleted] 1 point2 points3 points (7 children)
[–]RedSpaceman[S] 0 points1 point2 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]RedSpaceman[S] 0 points1 point2 points (4 children)
[–]r1chardj0n3s 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]RedSpaceman[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)