I'm trying to make a game using Pygame along with Tiled. The problem is that when I try to move my character it goes from one tile to the other (16x16 tile grid) so fast even when I lower the fps, it looks like it teleports from one tile to another (I have my movement incremented by 16 pixels so it matches with the map). What I want to achieve is sort of like what happens when you move in pokemon, you can see smooth animation as it moves from tile to tile (I use Pyganim for walking animation).
while running:
ColDetectposX = gameMap.get_tile_properties(((posX/16)+1),((posY/16)),1)
ColDetectnegX = gameMap.get_tile_properties(((posX/16)-1),((posY/16)),1)
ColDetectposY = gameMap.get_tile_properties(((posX/16)),((posY/16)+1),1)
ColDetectnegY = gameMap.get_tile_properties(((posX/16)),((posY/16)-1),1)
if facedown:
screen.blit(chardown,(posX,posY))
elif faceup:
screen.blit(charup,(posX,posY))
elif faceleft:
screen.blit(charleft,(posX,posY))
elif faceright:
screen.blit(charright,(posX,posY))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
walking = True
if event.key == pygame.K_RIGHT:
try:
if ColDetectposX['Collision'] == 'true':
walkright.blit(screen, (posX,posY))
facedown=False
faceup=False
faceleft=False
faceright=True
pass
else:
walkright.blit(screen, (posX,posY))
facedown=False
faceup=False
faceleft=False
faceright=True
posX+=16
except TypeError:
facedown=False
faceup=False
faceleft=False
faceright=True
posX+=16
elif event.key == pygame.K_LEFT:
try:
if ColDetectnegX['Collision'] == 'true':
walkleft.blit(screen, (posX,posY))
facedown=False
faceup=False
faceleft=True
faceright=False
pass
else:
facedown=False
faceup=False
faceleft=True
faceright=False
walkleft.blit(screen, (posX,posY))
posX-=16
except TypeError:
facedown=False
faceup=False
faceleft=True
faceright=False
walkleft.blit(screen, (posX,posY))
posX-=16
elif event.key == pygame.K_UP:
try:
if ColDetectnegY['Collision'] == 'true':
walkup.blit(screen, (posX,posY))
facedown=False
faceup=True
faceleft=False
faceright=False
pass
else:
facedown=False
faceup=True
faceleft=False
faceright=False
walkup.blit(screen, (posX,posY))
posY-=16
except TypeError:
facedown=False
faceup=True
faceleft=False
faceright=False
walkup.blit(screen, (posX,posY))
posY-=16
elif event.key == pygame.K_DOWN:
try:
if ColDetectposY['Collision'] == 'true':
walkdown.blit(screen, (posX,posY))
facedown=True
faceup=False
faceleft=False
faceright=False
pass
else:
facedown=True
faceup=False
faceleft=False
faceright=False
walkdown.blit(screen, (posX,posY))
posY+=16
except TypeError:
facedown=True
faceup=False
faceleft=False
faceright=False
walkdown.blit(screen, (posX,posY))
posY+=16
pygame.display.update()
fps.tick(11)
I hope I explained clearly what I wanted to do, if not I'll try to answer them best as I can. I don't know Object Oriented Programming, and I don't have time to learn due to my schedule so I hope you can help me without using classes. I also use python 3.4.4 if that is relevant.