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

2D spite positioning... was : [pygame] Positioning Objects in 3D




Actually all this reminds me of a question I ended up with after the
ld48.

I had a set of sprites.image's (tiles) for my 2d game that blitted to a
background surface for the 'squares' of my game, but I couldnt find a way to
'offset' the drawing onto the background surface:

EG, tiles    (0,0) (1,0) (2,0) ...   at  ( 0, 0) (32, 0) (64, 0) ...
             (0,1) (1,1) (2,1) ...       ( 0,32) (32,32) (64,32) ...
             (0,2) (1,2) (2,2) ...       ( 0,64) (32,64) (64,64) ...
              ...   ...   ...  ...        .....   .....   .....  ...

which is fine when the top left of the background is at (0,0), but if
I scroll my background down (so the top left is at (1,0)) then I need
to offset the drawing of the sprite images for that surface by
(0,-32) (so that (1,0) ends up being at (0,0), ie (0,32) is moved to (0,0))

I couldnt find a way to set a drawing offset for a surface. There is
surf.get_offset(), but I cant seem to set it:
  >>> s.get_offset()
  (0, 0)
  >>> s.set_offset(3,3)
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  AttributeError: set_offset
  >>> s.offset=(10,22)
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  TypeError: 'Surface' object has only read-only attributes (assign to
  .offset)
  >>> s.get_offset()
  (0, 0)

So I ended up keeping all my tiles in a sprite group and writing an
update case to move_ip the tile's rect value (which seems like a
really ugly hack!!)

(Yes, with such hackery, im pretty new at pygame.)
(Dont get me started on alpha channels and color keys. :)

cheers,
cam

--
 / `Rev Dr'   cam  at darkqueen.org            Roleplaying, virtual goth \
<   http://darkqueen.org        Poly, *nix, Python, C/C++, genetics, ATM  >
 \  [+61 3] 9809 1523[h]         skeptic, Evil GM(tm). Sysadmin for hire /
                      ---------- Random Quote ----------
Technological progress has merely provided us with more efficient means
for going backwards.
		-- Aldous Huxley