Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

Pygame builts a rect when I want to display sprite [duplicate]

$
0
0

I am writting a game in python and became stuck on a problem. I want to rotate an image but when i display it shows a light coloured rectangle around. Code isn't mine so i dont know what to do now. Please helpthe problem square

how do i get rid of it?

my code is

import pygamefrom pygame import Vector2srednica_ekranu = 800wysokosc_ekranu = 800class Grafika:    def __init__(self,obrot):        self.org = pygame.image.load("guzik.png").convert()        self.rect = self.org.get_rect()        self.img = self.org        self.obrot = obrot        self.pivot = Vector2(50,50)    def obroc(self):        sword_surface = self.org        sword_rect = sword_surface.get_rect()        # Create the rotation vector        rotation_vector = sword_surface.get_rect().center - self.pivot        # Rotate the rotation vector, and store as a new variable        rotated_vector = rotation_vector.rotate(self.obrot)        # Rotate the surface        rotated_sword_surface = pygame.transform.rotate(sword_surface, self.obrot)        # Relocate the surface        relocation_vector = rotated_vector - rotation_vector        sword_rect.center += relocation_vector        self.img = rotated_sword_surface        self.rect = sword_rect    def prawo(self):        self.obrot+=10        self.obrot%=360    def lewo(self):        self.obrot-=10        self.obrot%=360if __name__ == "__main__":    pygame.init()win = pygame.display.set_mode((srednica_ekranu, wysokosc_ekranu))pygame.display.set_caption("Grafiki")NOWAGRAFIKA = Grafika(0)run = Truewhile run:    pygame.time.delay(50)    for event in pygame.event.get():        if event.type == pygame.QUIT:            run = False    keys = pygame.key.get_pressed()    if keys[pygame.K_LEFT]:        NOWAGRAFIKA.lewo()    if keys[pygame.K_RIGHT]:        NOWAGRAFIKA.prawo()    if keys[pygame.K_UP]:        pass    if keys[pygame.K_SPACE] and p % 3 == 0:        pass    win.fill((0, 0, 0))    NOWAGRAFIKA.obroc()    win.blit(NOWAGRAFIKA.img, NOWAGRAFIKA.rect)    pygame.display.update()

Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>