Help! Background Color

0 te telo · April 5, 2015
Hi,for some reason I was working on a basic pygame project and my background appears to be black,however I specified it as white,please assist if possible.

Here is the code:

import pygame
pygame.init()

white = (255,255,255)
black=(0,0,0)
red=(255,0,0)

gameDisplay = pygame.display.set_mode((800,600))
pygame.display.set_caption('Slither')

gameExit=False

lead_x = 300
lead_y = 300

while not gameExit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameExit = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                lead_x -= 10

            if event.key == pygame.K_RIGHT:
                lead_x +=10

gameDisplay.fill(white)
pygame.draw.rect(gameDisplay, black,[lead_x,lead_y,10,100])
pygame.display.update()





pygame.quit()
quit()


Post a Reply

Replies

Oldest  Newest  Rating
0 The BM · April 5, 2015
this code

gameDisplay.fill(white)
pygame.draw.rect(gameDisplay, black,[lead_x,lead_y,10,100]https://www.thenewboston.com/images/emoticons/wink.png
pygame.display.update()


 must be in the while loop so the backgroundgets painted everytime the display gets updated 
0 te telo · April 5, 2015
Can you rewrite the code,please? I still cannot get the background to be white.
0 The BM · April 5, 2015

import pygame
pygame.init()

white = (255,255,255)
black=(0,0,0)
red=(255,0,0)

gameDisplay = pygame.display.set_mode((800,600))
pygame.display.set_caption('Slither')

gameExit=False

lead_x = 300
lead_y = 300

while not gameExit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameExit = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                lead_x -= 10

            if event.key == pygame.K_RIGHT:
                lead_x +=10

    gameDisplay.fill(white)
    pygame.draw.rect(gameDisplay, black,[lead_x,lead_y,10,100])
    pygame.display.update()





pygame.quit()
quit()

now it should work
0 te telo · April 6, 2015
Weird.Thanks,but it says "Invalid syntax" even after I remove:
https://www.thenewboston.com/images/emoticons/wink.png
0 The BM · April 6, 2015
for game dev. its better if you have the images localy stored and don't import them from the internet..
0 te telo · April 8, 2015
Thanks,man-It all works now.But for some reason,the text doesnt appear after I BLIT it:


import pygame 
import time

pygame.init()
white = (34,34,34)
black=(0,0,0)
red=(255,0,0)
led=45
pik=105
pygame.display.set_caption('Find the SLENDERMAN')
silver=(110,108,108)
yellow=(193,206,104)
yellow2=(213,230,100)
head_color=yellow2
eye_color=white
display_height=600
display_width=800
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption("Text")
myfont = pygame.font.SysFont("Comic Sans MS",290)
label = myfont.render("You Found M E !",290,white)

gameExit=False


lead_x = 300
lead_y = 300
lead_z=1
ps=-43+300
background_color=black
while not gameExit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameExit = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                lead_x -= 10
                print("LEFT")
                lead_z -=10
            if event.key == pygame.K_RIGHT:
                lead_x +=10
                print("RIGHT")
                lead_z +=10
            if event.key == pygame.K_UP:
                 lead_y -=10
                 print("UP")
                 lead_z -=10
            if event.key == pygame.K_DOWN:
                 lead_y +=10
                 print("DOWN")
                 lead_z +10
            if event.key == pygame.K_a:
                gameDisplay.fill(red)
                led +=10
                ps -=5
            if led == 95:
                background_color=red
                gameDisplay.blit(label, (400,300))
            if event.key == pygame.K_b:
                head_color=yellow
                eye_color=white
            if event.key == pygame.K_c:
                 head_color=white
                 eye_color=red
             
                
    gameDisplay.fill(background_color)
    pygame.draw.ellipse(gameDisplay, black,[-295+300-lead_z,-54+300,75,100])
    pygame.draw.ellipse(gameDisplay, red,[-285+300-lead_z,-35+300,20,34])
    pygame.draw.ellipse(gameDisplay, red,[-255+300-lead_z,-35+300,20,34])
    pygame.draw.rect(gameDisplay, silver,[300+lead_x,-35+lead_y,75,30])
    pygame.draw.ellipse(gameDisplay, yellow,[505+lead_z,ps,105,led])

    pygame.draw.circle(gameDisplay, head_color, (750+lead_z, 200), 75, 0)
    pygame.draw.ellipse(gameDisplay, eye_color,[680+lead_z,ps-80,50,led])
    pygame.draw.line(gameDisplay, white, [730+lead_z, 450], [730+lead_z,273], 10)
    

    pygame.display.update()

pygame.quit()
quit()
  • 1

Python

107,174 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator