Answer the question
In order to leave comments, you need to log in
Why did the window in pygame in python begin to close the previous window at startup?
how to make it so that each new launch of the pygame application closes the previous window. I thought that there was no such possibility and was sad.
Now, against the backdrop of events, I decided to digress, try to repeat what I did from the book, from memory. And for the first time ever, I encountered the closing of a new window of the previous one. No idea what I wrote. Experimentally found out that this is affected by the print function at the beginning of the method. I don't understand how it works. It is worth deleting or commenting it out and the new window no longer closes the previous one.
If anything, the code itself:
# main file
import pygame as pg
from pygame.sprite import Group
from settings import Settings
from ship import Ship
from alien import Alien
import engine
def start():
settings = Settings()
pg.init()
screen = pg.display.set_mode((settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT))
ship = Ship(screen, settings)
alien = Alien(screen, settings)
bullets = Group()
while True:
engine.check_all_events(screen, settings, ship, bullets)
engine.update_screen(screen, settings, ship, bullets, alien)
engine.update_bullets(bullets)
start()
import pygame as pg
from pygame.sprite import Group
class Alien():
def __init__(self, screen, settings):
self.screen = screen
self.screen_rect = self.screen
self.image = pg.image.load('img/alien.png')
self.rect = self.image.get_rect()
self.start_pos_X = self.rect.width
self.start_pos_Y = self.rect.height
self.aliens_amount_X = round(int((settings.SCREEN_WIDTH / self.rect.width) / 2))
def draw_alien(self):
print(self.aliens_amount_X)
for alien in range(self.aliens_amount_X):
self.rect.x = self.start_pos_X
self.rect.y = self.start_pos_Y
self.screen.blit(self.image, self.rect)
def draw_alien(self):
print(self.aliens_amount_X)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question