I used this youtube tutorial to make my sprite move and I was able to, but after running the code the movement of my sprite was very choppy. I tried other tutorial but I wasn’t able to make my sprite move again.
Here’s the code
import pygame
from sys import exit
import math
from Settings import *
pygame.init
#Game Initialization
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("A Swordmasters Journey")
clock = pygame.time.Clock()
#Player
ninja = pygame.image.load("Sprites/character/ninja.png").convert_alpha()
rect_1 = pygame.Rect(100, 100, 100, 100)
ninja_rect = ninja.get_rect()
ninja_mask = pygame.mask.from_surface(ninja)
#Game loop
run = True
while run:
clock.tick(FPS)
screen.fill((255, 255, 255))
pygame.draw.rect(screen, (255, 0, 0), rect_1)
screen.blit(ninja, ninja_rect)
key = pygame.key.get_pressed()
if key[pygame.K_a]:
ninja_rect.move_ip(-PLAYER_SPEED, 0)
if key[pygame.K_d]:
ninja_rect.move_ip(PLAYER_SPEED, 0)
if key[pygame.K_w]:
ninja_rect.move_ip(0, -PLAYER_SPEED)
if key[pygame.K_s]:
ninja_rect.move_ip(0, PLAYER_SPEED)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.flip()
pygame.quit()
New contributor
exstrix _ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
0