本文整理汇总了Python中sprite.Sprite.set_position方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.set_position方法的具体用法?Python Sprite.set_position怎么用?Python Sprite.set_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.set_position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadMap
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import set_position [as 别名]
def loadMap(filename):
# tileData = []
# tileImages = dict()
# impass = pygame.sprite.Group()
clearMap()
del tileData[:]
tileData[:] = []
impass.empty()
file = open(filename)
lines = file.readlines()
y = 0
for line in lines:
x = 0
line = line.replace('\n', '')
values = line.split(',')
for value in values:
parts = value.split(';')
tilePart = parts[0]
metadata = parts[1:] # The rest
if tilePart in tileImages:
newTile = {
'rect': pygame.Rect(x, y, x + TILE_SIZE, y + TILE_SIZE),
'surface': pygame.transform.scale(tileImages[tilePart], (TILE_SIZE, TILE_SIZE)),
'type': "tile"
}
tileData.append(newTile)
if tilePart == 'B':
b = Sprite('../resources/bush.png')
b.set_position(x, y)
b.rect.width = 20 #height and width are not setting properly. not sure why
b.rect.height = 20
impass.add(b)
if tilePart == 'R':
b = Sprite('../resources/rock.png')
b.set_position(x, y)
b.rect.width = 20
b.rect.height = 20
impass.add(b)
if len(metadata) > 0:
if metadata[0] == "player":
# TODO Move play here if the game just started
pass
elif metadata[0] == "baddy":
# TODO Put baddy here
pass
elif metadata[0] == "item":
if metadata[1] == "coin":
Item("../resources/coin.png").set_position(x, y)
x += TILE_SIZE
y += TILE_SIZE
for tile in tileData:
backgroundImage.blit(tile['surface'], tile['rect'])