'How to change a sprites rotation while a button is down [duplicate]
Just started using sprites, figured out how to make it blit, set the image, move with arrow keys, but I don't understand how to rotate it. I've tried some things only nothing seems to work or make sense, Here's my problem. I want the cube figure to rotate 90 degrees while pressing D or moving right, vise-versa for left. Some things have made sense but I still cannot rotate it. Here's my code, any sort of explanation helps, Thanks.
import pygame_textinput
import prompts
pygame.init()
textinput = pygame_textinput.TextInputVisualizer()
black = ("225, 225, 225")
font = pygame.font.SysFont("Comicsansms", 55)
display = pygame.display.set_mode((575, 375))
pygame.display.set_caption("Game")
clock = pygame.time.Clock()
pygame.key.set_repeat(200, 25)
ISSAC = pygame.image.load("issac.png")
class Issac(pygame.sprite.Sprite):
def __init__(self, image):
self.image = image
self.og_img = self.image
self.x = 0
self.y = 0
self.angle = 0
self.change_angle = 0
self.rect = self.image.get_rect()
def movement(self):
key = pygame.key.get_pressed()
ws = 3
if key[pygame.K_w]:
self.y -= ws
elif key[pygame.K_s]:
self.y += ws
if key[pygame.K_a]:
self.x -= ws
elif key[pygame.K_d]:
self.x += ws
self.change_angle = 90
def draw(self, display):
display.blit(self.image, (self.x, self.y))
def change(self):
if self.angle_change != 0:
self.angle = self.angle_change
issac = Issac(ISSAC)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
issac.movement()
display.fill((255, 255, 255))
issac.draw(display)
pygame.display.update()
clock.tick(60)```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
