[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Re-Blitting of already blitted items



Hey Elias. Sure, after your "screen.fill(White)" line, you want to add a call to a function like drawImagesInList(allpots). (Then get rid of the for loop after it.)

You'll want to define the drawImagesInList() function this:
def drawImagesInList(listOfImages):
    curx = 0
    for im in listOfImages:
        surface.blit(im, (curx, 0))
        curx += 50

Now you can pass drawImagesInList() a list of pygame.image objects and it will automatically draw them across the screen.

-Al


On Wed, Nov 28, 2012 at 8:41 PM, Elias Benevedes <benevedeselias@xxxxxxxxx> wrote:
Hello everyone

I was wondering if there was a way to make it so that you have items in a list representing images, a function adding to that list. Then, you have a function adding to that list. Then, you have a for loop blitting each of those pictures onto a surface, and adding 50 pix to the x amount for each iteration. The only problem is, every time the for loop iterates, every frame,  it adds 50 to the x amount AND re-blits the picture, moving it 50 pix to the right. I want to make it so that every time the for loop iterates, it checks to see if that item has already been blitted. If it has, don't re blit it. If not, blit it 50 pix to the right of the previously blitted image. Here is the code, if nothing above made sense to you ( I tend to ramble):

import pygame, sys
from pygame.locals import *

pygame.init()

def loadImage(image, posx, posy):
    screen.blit(image, (posx, posy))

screen = pygame.display.set_mode((640,480),0)
healthpot = pygame.image.load('Health.png')
manapot = pygame.image.load('Mana.png')
pygame.display.set_caption('Inventory test')
White = (255,255,255)
allpots = [manapot, healthpot]
curx = 0
cury = 0

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
    screen.fill(White)
    #screen.blit(healthpot, (0,0))
    #screen.blit(manapot, (50, 0))
    for i in allpots:
        loadImage(i, curx, cury)
        curx += 50
    pygame.display.flip()
    


--
"The validity of internet quotes are getting sketchy nowadays"
-Abraham Lincoln