0

this code is supposed to go to a different function which clears the screen when you hit z, and it does do that, but whenever I let go of z it switches back to the title function and redraws everything.

I'm trying to use it as a "hit this key to go to a new window" type thing and the screenfill is just a fill-in for now, so you can see why that's a problem. for the record I'm using python 3.6.

I've also already tried putting global start in the top of the title function, but then the z key does nothing. please and thanks!

import pygame
from pygame.locals import *
import random

pygame.init()

LOGO = pygame.image.load("kelogo.png")
savannah = pygame.image.load("savannah.png")
hitkey = pygame.image.load("hitkey.png")
display_width = 800
display_height = 600

white = (255, 255, 255)

game_display = pygame.display.set_mode((display_width, display_height))

start = False


def main_game():


    while start:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

    game_display.fill(white)           
    pygame.display.update()




def title():

    intro = False

    while not intro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        game_display.blit(savannah, ((0),(0)))
        game_display.blit(LOGO, ((0),(100)))
        game_display.blit(hitkey, ((130),(100)))

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_z:
                start = True
                main_game()

        pygame.display.update()


title()
main_game()
pygame.quit()
quit()
dannyB
  • 1
  • 1
  • Your game display and update is outside the while loop for one thing. Also your event catch for the z key is outside your event loop. – Nick is tired Apr 03 '17 at 21:40
  • thank you. I don't know how I didn't notice that. I fixed the formatting on that and added the global I mentioned and that fixed it!! – dannyB Apr 03 '17 at 21:42
  • You should restructure your code into so called *scenes*; have a look at this answer: http://stackoverflow.com/a/14727074/142637 – sloth Apr 04 '17 at 12:15

0 Answers0