Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

Python
#!/usr/bin/python

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:
######TITLE#####
    pygame.display.set_caption("Gravity")

#########Size of screen########
    size = width, height = 1366, 768
    screen = pygame.display.set_mode(size)
    screen.fill(green)
    ######KEY PRESS EVENTS####
    ##GET MOUSE POSITION
    mx, my = pygame.mouse.get_pos()
    #print mx, my
    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.
Posted
Updated 27-Mar-14 14:02pm
v2
Comments
nbe412 27-Mar-14 20:31pm    
Well, can you post your solution it would be helpful :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900