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

Re: [pygame] Native PyGame method for automatically scaling inputs to a surface resolution?



What is the purpose to having calculations done with a size that's 10 times larger? If it's just precision, the solution could be simply to use floats for the calculations and convert to ints as necessary.

Or, you could write some simple functions or methods that divide the x and y by 10 and then pass the new values to the appropriate Pygame methods. Or, if you really want to use the normal Pygame methods, just integer-divide the values as you pass them. Even better, you could make a derived class and override the Pygame methods with more appropriate ones (a technique commonly used with wxPython) like so:

def blit(self, source, dest, area=None, special_flags=0):
# Change dest so that its x and y are divided by 10
pretend_this_function_does_what_you_want()

pygame.Surface.blit(self, source, dest, area, special_flags)

One last possibility that I can think of is to scale up your graphics for 1000x1000 and then scale the window surface every time you want to draw it. That is, draw to a 1000x1000 surface, but shrink it to 100x100 when it's displayed. I would only recommend this if you find it easy to implement and any performance hit is negligible or unimportant.

Anyway, I hope that helps!

--- On Fri, 9/23/11, Mac Ryan <quasipedia@xxxxxxxxx> wrote:

From: Mac Ryan <quasipedia@xxxxxxxxx>
Subject: [pygame] Native PyGame method for automatically scaling inputs to a surface resolution?
To: pygame-users@xxxxxxxx
Date: Friday, September 23, 2011, 8:29 AM

Hello,

    back July, I posted a question on StackOverflow titled that so
far still did not get any answer. So - although I believe the answer is
quite simply "NO" - I thought to repost it here:

----------------

In my program (which uses pygame to draw objects on the video) I have
two representation of my world:

- A physical one that I use to make all the calculations involved in the
  simulation and in which objects are located on a 1000x1000 metres
  surface.
- A visual one which I use to draw on the screen, in which my objects
  are located in a window measuring 100x100 pixels.

What I want to achieve is to be able to pass to my pygame drawing
functions (which normally accept inputs in pixels) my
physical/real-word coordinates. In other words, I would like to be able
to say:

Draw a 20m radius circle at coordinates (200m, 500m)
using the precise pygame syntax:

pygame.draw.circle(surface, (255,255,255), (200,500), 20)
and get my circle of 2px radius at centred on pixels (20,50).

----------------

If you are on SO and would like to answer there [too], I'll be happy to
dispense upvotes! ;) http://stackoverflow.com/q/6807459/146792