Why cant my program blit the same image that it loaded multiple times?
Imagea = pygame.image.load('imagea.png')
Imageb = pygame.image.load('imageb.png')
Inside gameloop
deck = abaa
for i in deck:
for position in positions:
if(i) == deck[0]:
if(i == a):
gamedisplay.blit(imagea, positions[0])
elif(i == b):
gamedisplay.blit(imageb, positions[0])
if(i) == deck[1]:
if(i == a):
gamedisplay.blit(imagea, positions[1])
elif(i == b):
gamedisplay.blit(imageb, positions[1])
if(i) == deck[2]:
if(i == a):
gamedisplay.blit(imagea, positions[2])
elif(i == b):
gamedisplay.blit(imageb, positions[2])
if(i) == deck[3]:
if(i == a):
gamedisplay.blit(imagea, positions[3])
elif(i == b):
gamedisplay.blit(imageb, positions[3])
What seems to occur is only deck 0 and deck 1 show imagea and imageb. However, deck 2 and 3 does not show up at position[2] or position[3].
deckis a list andiis an element of the list. It is not necessary to evaluated if is an element of the list, of course it is. This evaluation is the issue. Note, ifiis multiple times indeck(e.g. at index 0 and 2), thenif i == deck[2]:is never evaluated, becauseif i == deck[o]:is evaluatedTruefirst.In the following, I assume that
deckandpositionhave the same number of elements.Either use
enumerateto traversedeckand get a tuple contaning the index of the element and the element itself:Or use
zipto traversedeckandpositionssimultaneously: