#๐ Pygame basic movement error
25 messages ยท Page 1 of 1 (latest)
@frail vortex
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Hi I am trying to make basic movement for a rectangle but why wont it move when I press the key corresponding to movement?
import pygame
pygame.init()
SCREEN_HEIGHT = 500
SCREEN_WIDTH = 600
screen = pygame.display.set_mode((SCREEN_HEIGHT, SCREEN_WIDTH))
run = True
player = pygame.Rect((250, 250, 50, 50))
while run:
pygame.draw.rect(screen, (255, 0, 0), player)
key = pygame.key.get_pressed()
if key[pygame.K_a] == True:
player.move(-1, 0)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
pygame.quit()
Hi I am trying to make basic movement for a rectangle but why wont it move when I press the key corresponding to movement?
first of all, you dont need to check if this is true if key[pygame.K_a] == True
you can just have it as if key[pygame.K_a]
ye
and also, you need to assign the player to the player.move
lgtm
so it would be player=player.move(-1, 0)
what?
what?
where would you
can do
put that
his current code says player.move(-1, 0) when it should be player = player.move(-1, 0)
i see nothing wrong with the code
what?
oh yeah
but i think he should move in place
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.