Jump to content

How to display more than 3 images in python script?

ZaBoss

Hey, I am having trouble with displaying more than 1 image in this python script, please help?! Thanks. Here is the script. I already have 1 image and the background, please please help!

 

import pygame
 
pygame.init()
 
display_width = 600
display_height = 600
 
black = (0,0,0)
white = (0,0,0)
 
 
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('8Bit Warfare')
clock = pygame.time.Clock()
 
 
bgImg = pygame.image.load('improvedbackground.jpg')
carImg = pygame.image.load('mothership.png')
 
x = (display_width/4)
y = (display_height/4)
 
def car(x,y):
    gameDisplay.blit(carImg, (x,y))
    
crashed = False
 
while not crashed:
 
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            crashed = True
 
 
    gameDisplay.fill(white)
    gameDisplay.blit(bgImg,(0,0))
    car(x,y)
    pygame.display.update()
    clock.tick(60)
 

RIG:  CPU: Intel Core i5-4690K CPU Cooler: Corsair H80i Motherboard: ASRock Fatal1ty Z97 Killer ATX Memory: G.Skill Ripjaws Series 8GB Storage: Seagate Barracuda 1TB Internal HDD SSD: Samsung 840 Series 120GB 2.5" SSD Video Card: Zotac GeForce GTX 970 4GB Video Card Case: Corsair 780T PSU: NZXT HALE82 850W 80+ Bronze Monitor: LG 34UM95-P Keyboard: Steelseries Apex Keyboard Mouse: Razer Taipan Mouse Mat: Razer Vespula Sound: Cyber Acoustics CA-3090, Corsair Vengeance 2100 :  1998.40 Euro

Link to comment
Share on other sites

Link to post
Share on other sites

@jman629 Hey man, I really need your help. You were really helpful last time it would be amazing if you could help me with this.

RIG:  CPU: Intel Core i5-4690K CPU Cooler: Corsair H80i Motherboard: ASRock Fatal1ty Z97 Killer ATX Memory: G.Skill Ripjaws Series 8GB Storage: Seagate Barracuda 1TB Internal HDD SSD: Samsung 840 Series 120GB 2.5" SSD Video Card: Zotac GeForce GTX 970 4GB Video Card Case: Corsair 780T PSU: NZXT HALE82 850W 80+ Bronze Monitor: LG 34UM95-P Keyboard: Steelseries Apex Keyboard Mouse: Razer Taipan Mouse Mat: Razer Vespula Sound: Cyber Acoustics CA-3090, Corsair Vengeance 2100 :  1998.40 Euro

Link to comment
Share on other sites

Link to post
Share on other sites

If not to late...

#Code with comments above are what I added.#If you want to add a fourth image to screen create new variables and functions like I did.import pygame pygame.init() display_width = 600display_height = 600 black = (0,0,0)white = (0,0,0)  gameDisplay = pygame.display.set_mode((display_width,display_height))pygame.display.set_caption('8Bit Warfare')clock = pygame.time.Clock()  bgImg = pygame.image.load('improvedbackground.jpg')carImg = pygame.image.load('mothership.png') #Loaded another image and set equal to extraImg variable.#extraimage.png will have to be created and placed in the same folder this code is in.#when creating extraimage.png you will have to set the resoltion(width,height) at a reasonable size.extraImg = pygame.image.load('extraimage.png') x = (display_width/4)y = (display_height/4) def car(x,y):    gameDisplay.blit(carImg, (x,y)) #Created another function to put image on screen.def extra(x, y):    #x and y variables made smaller so not over car image.    x = x/2    y = x/2    #Blit the image to screen like you did in the car function.    gameDisplay.blit(extraImg,(x,y))    crashed = False while not crashed:     for event in pygame.event.get():        if event.type == pygame.QUIT:            crashed = True      gameDisplay.fill(white)    gameDisplay.blit(bgImg,(0,0))    car(x,y)    #Invoke or call the extra function.    extra(x,y)    pygame.display.update()    clock.tick(60)  #Hope this helps!  
Link to comment
Share on other sites

Link to post
Share on other sites

import pygame

 

pygame.init()

 

display_width = 600

display_height = 600

 

black = (0,0,0)

white = (0,0,0)

 

 

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

pygame.display.set_caption('8Bit Warfare')

clock = pygame.time.Clock()

 

 

bgImg = pygame.image.load('improvedbackground.jpg')

carImg = pygame.image.load('castle.jpg')

extraImg = pygame.image.load('extraimage.jpg')

 

x = (display_width/4)

y = (display_height/4)

 

def car(x,y):

    gameDisplay.blit(carImg, (x,y))

 

 

def extra(x,y):

    x = x/2

    y = x/2

    gameDisplay.blit(extraImg,(x,y))

    

crashed = False

 

while not crashed:

 

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            crashed = True

 

 

    gameDisplay.fill(white)

    gameDisplay.blit(bgImg,(0,0))

    car(x,y)

    extra(x,y)

    pygame.display.update()

    clock.tick(60)

 

pygame.quit()

quit()

 

 

 

 

 

 

It says " Error : Out of memory  

 

 Do you know what this means?

RIG:  CPU: Intel Core i5-4690K CPU Cooler: Corsair H80i Motherboard: ASRock Fatal1ty Z97 Killer ATX Memory: G.Skill Ripjaws Series 8GB Storage: Seagate Barracuda 1TB Internal HDD SSD: Samsung 840 Series 120GB 2.5" SSD Video Card: Zotac GeForce GTX 970 4GB Video Card Case: Corsair 780T PSU: NZXT HALE82 850W 80+ Bronze Monitor: LG 34UM95-P Keyboard: Steelseries Apex Keyboard Mouse: Razer Taipan Mouse Mat: Razer Vespula Sound: Cyber Acoustics CA-3090, Corsair Vengeance 2100 :  1998.40 Euro

Link to comment
Share on other sites

Link to post
Share on other sites

Do you have enough memory on your system? Most likely you should have enough. Are you running 64bit python with 32bit pygame or viscera? I think they may have to be the same. Also do other python programs run? And do other python pygame programs run? 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Do you have enough memory on your system? Most likely you should have enough. Are you running 64bit python with 32bit pygame or viscera? I think they may have to be the same. Also do other python programs run? And do other python pygame programs run? 

I'm having a bit of trouble checking if it is the 64bit or the 32bit version, 

i run on a mac. Sorry if this annoys you.

RIG:  CPU: Intel Core i5-4690K CPU Cooler: Corsair H80i Motherboard: ASRock Fatal1ty Z97 Killer ATX Memory: G.Skill Ripjaws Series 8GB Storage: Seagate Barracuda 1TB Internal HDD SSD: Samsung 840 Series 120GB 2.5" SSD Video Card: Zotac GeForce GTX 970 4GB Video Card Case: Corsair 780T PSU: NZXT HALE82 850W 80+ Bronze Monitor: LG 34UM95-P Keyboard: Steelseries Apex Keyboard Mouse: Razer Taipan Mouse Mat: Razer Vespula Sound: Cyber Acoustics CA-3090, Corsair Vengeance 2100 :  1998.40 Euro

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×