Jonathan
Jonathan

Reputation: 1508

Pygame Large Surfaces

I'm drawing a map of a real world floor with dimensions roughly 100,000mm x 200,000mm.

My initial code contained a function that converted any millimeter based position to screen positioning using the window size of my pygame map, but after digging through some of the pygame functions, I realized that the pygame transformation functions are quite powerful.

Instead, I'd like to create a surface that is 1:1 scale of real world and then scale it right before i blit it to the screen.

Is this the right way to be doing this? I get an error that says Width or Height too large. Is this a limit of pygame?

Upvotes: 1

Views: 2255

Answers (2)

user2963623
user2963623

Reputation: 2295

If your map is not dynamic, I would suggest draw a map outside the game and load it in game. If you plan on converting the game environment into a map, It might be difficult for a large environment. 100,000mm x 200,000mm is a very large area when converting into a pixels. I would suggest you to scale it down before loading.

As for scaling in-game, you can use pygame.transform.rotozoom or pygame.transform.smoothscale.

Also like the first answer mentions, scaling can take significant memory and time for very large images. Scaling a very large image to a very small image can make the image incomprehensible.

Upvotes: 0

beiller
beiller

Reputation: 3135

I dont fully understand your question, but to attempt to answer it here is the following.

No you should not fully draw to the screen then scale it. This is the wrong approach. You should tile very large surfaces and only draw the relevant tiles. If you need a very large view, you should use a scaled down image (pre-scaled). Probably because the amount of memory required to draw an extremely large surface is prohibitive, and scaling it will be slow.

Convert the coordinates to the tiled version using some sort of global matrix that scales everything to the size you expect. So you should also filter out sprites that are not visible by testing their inclusion inside the bounding box of your view port. Keep track of your view port position. You will be able to calculate where in the view port each sprite should be located based on its "world" coordinates.

Upvotes: 2

Related Questions