本文整理汇总了Python中pyglet.sprite.Sprite.imagelayer方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.imagelayer方法的具体用法?Python Sprite.imagelayer怎么用?Python Sprite.imagelayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyglet.sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.imagelayer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadmap
# 需要导入模块: from pyglet.sprite import Sprite [as 别名]
# 或者: from pyglet.sprite.Sprite import imagelayer [as 别名]
def loadmap(self):
tw = self.tmx_data.tilewidth
th = self.tmx_data.tileheight
mh = self.tmx_data.height - 1
draw_rect = self.draw_rect
draw_lines = self.draw_lines
offset_x, offset_y = 0, 0
rect_color = (255, 0, 0)
poly_color = (0, 255, 0)
for l in self.tmx_data.layers:
if isinstance(l, TiledTileLayer) and l.name == "Obstacles":
logging.debug("Removing obstacles from game grid.")
for x, y, image in l.tiles():
self.window.game.tiles_no_walk.append((x, y))
self.window.game.tiles_no_build.append((x, y))
elif isinstance(l, TiledTileLayer) and l.name == "Flightpath":
logging.debug("Fligh path included in map, importing.")
self.window.game.flightgrid = []
for x, y, image in l.tiles():
self.window.game.flightgrid.append((x, y))
for layer in self.tmx_data.visible_layers:
nw, nb = False, False # nowalk, nobuild
spawn, goal = False, False
if layer.name == "Background":
batch = self.window.batches["bg1"]
elif layer.name == "Background2":
batch = self.window.batches["bg2"]
elif layer.name == "Obstacles":
batch = self.window.batches["obs"]
# nw, nb = True, True
elif layer.name == "Spawn":
batch = self.window.batches["obs"]
nb = True
spawn = True
elif layer.name == "Goal":
batch = self.window.batches["obs"]
nb = True
goal = True
elif layer.name == "Foreground":
batch = self.window.batches["fg"]
else:
logging.error("Layer not recognized, skipping {0}".format(
layer.name
)
)
break
# draw map tile layers
if isinstance(layer, TiledTileLayer):
if not layer.name == "Obstacles":
# iterate over the tiles in the layer
for x, y, image in layer.tiles():
if nw:
self.window.game.tiles_no_walk.append((x, y))
if nb:
self.window.game.tiles_no_build.append((x, y))
gx, gy = x, y
y = mh - y
x = x * tw
y = y * th
x += offset_x
y += offset_y
# image.blit(x * tw, y * th)
image = center_image(image)
sprite = Sprite(image, batch=batch, x=x, y=y)
sprite.imagelayer = False
sprite.gx, sprite.gy = gx, gy
self.sprites.append(sprite)
if spawn:
self.window.game.spawn = (gx, gy)
elif goal:
self.window.game.goal = (gx, gy)
# draw object layers
elif isinstance(layer, TiledObjectGroup):
# iterate over all the objects in the layer
for obj in layer:
logging.info(obj)
# objects with points are polygons or lines
if hasattr(obj, 'points'):
draw_lines(poly_color, obj.closed, obj.points, 3)
# some object have an image
elif obj.image:
# obj.image.blit(obj.x, pixel_height - obj.y)
sprite = Sprite(image, batch=batch, x=x * tw, y=y * th)
# draw a rect for everything else
else:
draw_rect(rect_color,
(obj.x, obj.y, obj.width, obj.height), 3)
# draw image layers
elif isinstance(layer, TiledImageLayer):
if layer.image:
#.........这里部分代码省略.........