Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygame zooming/scrolling window

Im currently working on a project with pygame and am in need of being able to view part of a surface, moving around, zooming in and out ect

Can anyone recommend a way of achieving this efficently, i have it working in a convoluted method at the moment but it is too slow and reduces the game to about 1fps when zoomed out to view the whole area. (my version of only scrolling and no zooming works fine with no lagging)

Looking though the docs pygame.transform.scroll looks promising but i am unsure how i would correctly implement it with pygame.transform.scale for zooming in and out

Any help welcome

update: I fiddled around for a bit and got it working scaleing objects and their positions before bliting them. I have now hit the problem that the scaling looks unatural because of the low resolution of the pygame scroll wheel events so I am now trying to impliment some kind of smoothing.

like image 431
Hugoagogo Avatar asked Nov 14 '22 02:11

Hugoagogo


1 Answers

I am not entirely sure what, exactly, you are doing. I can however say that it doesn't sound like you are approaching the problem in a way that fits Pygame.

It sounds to me like you are relying on software scaling algorithms, which is what Pygame uses, to scale a large picture (the entire game world) to a much smaller size. Anything like that, for large surfaces, and on each frame, is going to greatly strain your CPU.

If zooming is really important, I'd recommend a change to a library that has hardware accelerated scaling, i.e pyglet. After all, how often did you see games zoom out in the days before GPUs? Virtually never, that's how often.

like image 186
porgarmingduod Avatar answered Dec 17 '22 23:12

porgarmingduod