I'm new to pygame, and I am having some trouble. I am making a simple program where there are 2 sprites. One of the sprites is locked in place upon spawning, and acts as a solid. The other is a ball that when spawned on top of the other sprite, it will bounce, and follow the laws of gravity. Here is my code:
import time
import termcolor
import sys
import pygame
import pygame.mixer
from pygame.locals import *
pygame.init()
box = pygame.image.load("blackbox.png")
def gravity(speed):
speed = x+5
white = (255,255,255)
black = (0,0,0)
green = (0,255,0)
loop = 1
while loop == 1:
pygame.display.set_caption("Gravity")
size = width, height = 1366, 768
screen = pygame.display.set_mode(size)
screen.fill(green)
mx, my = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
sys.exit()
if event.type == pygame.QUIT:
sys.exit()
if event.type == MOUSEBUTTONUP:
if event.button == 3:
screen.blit(box,(mx,my))
screen.blit(box,(100,100))
pygame.display.flip()
The Program Runs Fine Except When I Try To Spawn The First Sprite. If You Have Basic Knowledge of Pygame, you know that the screen has to update when you are animating. Where it
says pygame.display.flip() is the line that updates the screen. When executing the program, all is well until I right click. The sprite spawns, and immediately disappears. I know that #this is because the background updates over top of it. What I Need is a way to make sure the sprite stays visible through the entire program.