以下は、pygletを使用してレンダリングされる2Dアイソメタイルのマップの部分的なクラス定義です。
class Map(object):
origin = 0
drytile = tile.dry
wettile = tile.wet
def __init__(self, left=8, right=8):
self.grid = np.array(([None] * left, [None] * right), dtype=object)
self._setup_grid()
def __iter__(self):
"""return tiles in the order in which they should be rendered"""
# get number of diagonals
ndiags = (np.max(self.grid.shape) * 2) -\
(1 + (np.max(self.grid.shape) - np.min(self.grid.shape)))
# get iterator to go through diagonals in back-to-front order
offsets = xrange(-(ndiags / 2), ndiags / 2 + 1)
# iterate in render order
for off in offsets:
for tile in np.flipud(self.grid).diagonal(off)[::-1]:
yield tile
これらのタイルは、次の図のように、後ろから前にレンダリングする必要があります。
私のクラス定義では、原点は最上位のタイル(tile a
)を参照しているためleft
、クラスで定義されている次元はに沿ったベクトル[a b d g]
であり、 right
次元はに沿ったベクトル[a c f j]
です。
多数のタイルをレンダリングするつもりなので、これは私のアプリケーションの速度が重要な部分です。指定された順序でタイルを反復処理するより速い方法はありますか?ネストされたループのヘルプを削除できますか?
どうもありがとう!