Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot draw sprite to screen
    primarykey
    data
    text
    <p>I started creating my first pygame game that uses multiple modules(.py files) for easier understanding the code so here we go.</p> <p>main.py</p> <pre><code>import pygame,sys from Player import * from groups import * from constants import * from Events import * pygame.init() screen = pygame.display.set_mode(size) player = Player() player.add_to_group() while True: player.draw(screen) event = Event() </code></pre> <p>Player.py</p> <pre><code>import pygame from groups import * class Player(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([30,30]) self.image.fill([255,0,0]) self.rect = self.image.get_rect() def move_player(self): key = pygame.key.get_pressed() if key[pygame.K_DOWN]: self.rect.y += 1 elif key[pygame.K_UP]: self.rect.y -= 1 elif key[pygame.K_RIGHT]: self.rect.x += 1 elif key[pygame.K_LEFT]: self.rect.x -= 1 def add_to_group(self): all_sprite_list.add(self) def remove_from_group(self): all_sprite_list.remove(self) def draw(self,surface): surface.blit(self.image,(0,0)) </code></pre> <p>groups.py</p> <pre><code>import pygame all_sprite_list = pygame.sprite.Group() </code></pre> <p>constants.py</p> <pre><code>import pygame size = width,heighth = 700,400 </code></pre> <p>Events.py</p> <pre><code>import pygame,sys class Event(object): def __init__(self): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() </code></pre> <p>And the result should be a red square in the top left corner representing the player. But no matter I do it, I don't get any errors but it only just shows a blank black window.</p> <p>I tried to fix it several times (like using .draw to draw the entire "all_sprite_list") but nothing worked.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload