I have a spritesheet for a game I'm making and it's for one of the enemies in the game. I loaded the spritesheet correctly (I think) and I got the code make it appear and move to work. When I run the code though, the enemy doesn't appear.
The code for loading the spritesheet:
enemySheet = pygame.image.load("resources/Alien.png").convert_alpha()
transColor = (255,255,255)
cells = []
for n in range(3):
width, height=(36,32)
rect = pygame.Rect(n * width, 0, width, height)
image = pygame.Surface(rect.size, pygame.SRCALPHA).convert_alpha()
image.blit(enemySheet, (0,0), rect)
cells.append(image)
enemyImg = cells[0]
enemyImg.set_colorkey(transColor)
enemy = enemyImg.get_rect()
enemy.center = (216,216)
The code for spawning the enemy:
if timeTillEnemy <= 0:
enemies.append([0,50,0])
timeTillEnemy = random.randrange(0,800)
timeTillEnemy -= 1
Here's the code for the enemy's movement:
for enemy in enemies:
index = 0
enemy[0] += 2
if enemy[1] >= 270:
enemy[2] = -2
else:
enemy[2] = enemy[2] + 0.01
enemy[1] = enemy[1] + enemy[2]
screen.blit(enemyImg, (enemy[0],enemy[1]))
if enemy[0] > 470:
enemies.pop(index)
index += 1
I haven't gotten around to animating it yet so that's why it isn't here. There is no error message and everything runs just fine. The enemy isn't appearing though so that's why I'm here. All help is appreciated.