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

Re: [pygame] Isometric Math



-How do I do "picking," identifying the tile or character a user has
clicked on? I can imagine calculating it for a flat iso landscape, but
taking height into account all I've come up with so far is to save a
bunch of bounding rectangles and test them inefficiently.

I would recommend that you use something like:

current_mouse_pos = pygame.mouse.get_pos()
for tile in list_of_tiles_sorted_in_z_order_descending: # z-order in this case being screen depth.
      if tile.colliderect(current_mouse_pos):
          # do stuff

Of course, you would probably want to either replace colliderect with a collidepoly function or cheat by making the clickable area smaller than the isorect.

-How do I use this engine smoothly given that I'm loading a "zone"
around the player and the 8 around that zone, like an endless treadmill?
In my previous 2D code I had a sort of "playmat" surface that I drew to
once, then scrolled through. Now if I draw that and then the sprites,
they'd appear in front of things that should obscure them. So should I
draw each tile individually, caching those drawings between frames for
speed? This seems like it'd also let me do things like have a
translucent water layer.

From what I understand about older sprite games, it was only ever necessary to blit one row or column of tiles or sprites on each screen border, not entire sheets.  You should be able to do this while still having good performance, although you will have to deal with special cases where the height of a tile causes it to appear onscreen sooner than its y coord would suggest.

-How can I make sure the camera follows the player's sprite? I worked it
out in 2D but am not sure it'll work in iso, especially since the player
will go up and down.

Shouldn't make any difference at all.  You're basing the view on the sprites screen surface x/y, innit?  It should use the same function you're using with flat worlds.

-I can't do smooth rotation with iso, but I could rotate the
height/texture maps to switch instantly between 4 angles, right?

Yes, you can.  Don't know the math behind it, but I know there's an algo out there for doing 90 degree rotations of tilemaps.

--
Andrew Ulysses Baker
"failrate"