I'm new to python and I'm trying to make a list of sprites, all with the same texture but with different positions. I try and append the sprites with new positions onto my list, but all the sprites in the list end up having the same position. Any help?
def stageLoader():
try:
texture = sf.Texture.from_file("Brown Block.png")
except:
exit(1)
tileSprite = sf.Sprite(texture)
spriteMap = []
for xtile in range(8):
for ytile in range(4):
tileSprite.position = (xtile*100, ytile*170)
spriteMap.append(tileSprite)
return spriteMap
stageMap = stageLoader()
for tile in range(len(stageMap)):
print(stageMap[tile].position)
My output is this:
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y
700.0x, 510.0y