本文整理汇总了Python中layer.Layer.map方法的典型用法代码示例。如果您正苦于以下问题:Python Layer.map方法的具体用法?Python Layer.map怎么用?Python Layer.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类layer.Layer
的用法示例。
在下文中一共展示了Layer.map方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startElement
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import map [as 别名]
def startElement(self, name, attrs):
if name == 'map':
# We can get some basic info about the map from this tag
if 'width' in attrs.getNames():
# Be careful here, attrs.getValue always return a
# string, so always convert afterwards
self.map.size[0] = int(attrs.getValue('width'))
if 'height' in attrs.getNames():
self.map.size[1] = int(attrs.getValue('height'))
# remember that we are in this tag
self.inMap = True
# Tileset tag
# Add a new tileset to the map with all the options
if name == 'tileset' and self.inMap == True:
# Make a new blank tileset.
tileset = Tileset()
# Attach the map to the tileset
tileset.map = self.map
# Fill it with some of the new info in this tag
if 'tilewidth' in attrs.getNames():
tileset.tileSize[0] = int(attrs.getValue('tilewidth'))
if 'tileheight' in attrs.getNames():
tileset.tileSize[1] = int(attrs.getValue('tileheight'))
if 'name' in attrs.getNames():
tileset.name = attrs.getValue('name')
# K, add this tileset to the loaded map
self.map.tilesets.append(tileset)
# We can add things from nested tags into it later.
self.inTileset = True
# Image Tag
# We should add this image to the current tileset
if name == 'image' and self.inTileset:
# Find the location of the image and load it
if 'source' in attrs.getNames():
self.map.tilesets[-1].load(attrs.getValue('source'), self.map.tilesets[-1].tileSize)
# K, done... assuming that image loaded.
# Layer Tag
if name == 'layer' and self.inMap:
# Make a new layer
layer = Layer()
# Attach layer to map
layer.map = self.map
# Get the name of the layer
if 'name' in attrs.getNames():
layer.name = attrs.getValue('name')
# Width and Height
if 'width' in attrs.getNames():
layer.width = int(attrs.getValue('width'))
if 'height' in attrs.getNames():
layer.height = int(attrs.getValue('height'))
# Add the new layer to the map
self.map.layers.append(layer)
# We're inside the layer tag now
self.inLayer = True
# Properties
if name == 'properties' and self.inLayer:
self.inProperties = True
if name == 'property' and self.inProperties and self.inLayer:
# Add this property to the current layer
if 'name' in attrs.getNames():
if attrs.getValue('name') == 'Solid':
if 'value' in attrs.getNames():
if attrs.getValue('value') == '1':
self.map.layers[-1].solid = True
# Data Tag
if name == 'data' and self.inLayer:
# Find out how the data is encoded
if 'encoding' in attrs.getNames():
self.dataEncoding = attrs.getValue('encoding')
# Flush the buffer
self.dataBuffer = ''
# Inside data, now we can load the layer data
self.inData = True