Я следовал этому уроку: https://www.trccompsci.online/mediawiki/index.php?title=PyGame_Platform&diff=5514&oldid=5513
и столкнулся с этой проблемой
Игрок не двигается, и карта перемещается.
Я не знаю, откуда возникла эта проблема.
вот код:
import pygame
import sys
import os
import pytmx
from pytmx.util_pygame import load_pygame
os.environ["SDL_VIDEO_CENTERED"] = "1"
pygame.init()
SCREENWIDTH = 1000
SCREENHEIGHT = 900
SCREENSIZE = [SCREENWIDTH, SCREENHEIGHT]
SCREEN = pygame.display.set_mode(SCREENSIZE)
tiled_map = load_pygame('Test2.tmx')
tilewidth = tiled_map.tilewidth
tileheight = tiled_map.tileheight
CAMERA = tiled_map.get_object_by_name("Player")
pygame.display.set_caption("My first game in pygame")
collision = tiled_map.get_layer_by_name('PlatForm')
player = pygame.image.load("p1_front.png").convert_alpha();
while True:
for events in pygame.event.get():
if events.type == pygame.QUIT:
pygame.quit()
sys.exit()
for layer in tiled_map.layers:
if isinstance(layer, pytmx.TiledTileLayer):
for x, y, tile in layer.tiles():
if (tile):
SCREEN.blit(tile, [(x*tilewidth) - CAMERA.x +(SCREENWIDTH/2) , (y*tileheight) - CAMERA.y + (SCREENHEIGHT/2)])
if isinstance(layer, pytmx.TiledObjectGroup):
for object in layer:
if (object.name == 'Player'):
SCREEN.blit(player, [object.x - CAMERA.x +(SCREENWIDTH/2), object.y - CAMERA.y + (SCREENHEIGHT/2)])
pygame.display.update()
pos = [0, 0]
PRESSED = pygame.key.get_pressed()
if PRESSED[pygame.K_LEFT]:
pos[0] -= 10
elif PRESSED[pygame.K_RIGHT]:
pos[0] += 10
if PRESSED[pygame.K_UP]:
pos[1] -= 10
elif PRESSED[pygame.K_DOWN]:
pos[1] += 10
tiled_map.get_object_by_name("Player").x += pos[0]
tiled_map.get_object_by_name("Player").y += pos[1]
заранее благодарю за помощь.