1SDANTheMan
1SDANTheMan

Reputation: 5

Having Trouble Blitting Image From Dictionary

So I'm trying to get into using Pygame, but all of the tutorials I can find online utilize only one file. I played around with ideas on how I can load all of the images in a single function. and decided on saving them in a Dictionary. Problem is, when I try to paste the image from the dictionary, I get the following error:

Traceback (most recent call last):
  File "J:\Growth of Deities\Main.py", line 32, in <module>
pygame.Surface.blit(Sprites["TileWastelandBasic"], (0, 0))
TypeError: argument 1 must be pygame.Surface, not tuple

So I played around with the code a bit and googled it for an hour or so, but I can't figure out why I'm getting an error. I assume it's because I can't save images in dictionaries, but I'm not certain. Does anyone have any ideas on how to fix it?

My Main File: import pygame from Startup import LoadTextures pygame.init()

#Sets the color White
WHITE = (255, 255, 255)

#Sets screen size Variable
size = (900, 900)
#Sets Screen Size
screen = pygame.display.set_mode(size)

#Sets name of Game
pygame.display.set_caption("Growth of Deities")

closeWindow = False
clock = pygame.time.Clock()

Sprites = LoadTextures.Load()


while not closeWindow:
    #Repeat while game is playing
    for event in pygame.event.get():
        #Close Window if you close the window
        if event.type == pygame.QUIT:
            closeWindow = True

    #Logic Code

    #Rendering Code
    pygame.Surface.blit(Sprites["TileWastelandBasic"], (0, 0))

    #Clear Screen
    screen.fill(WHITE)

    #Update Screen
    pygame.display.flip()

    #Set Tick Rate
    clock.tick(60)
#Closes Game
pygame.quit()

My Image Loading File:

import pygame
import os, sys


def Load():
    Sprites = {}

WastelandSprites = 'Assets\Textures\Tile Sprites\Wasteland'

    Sprites["TileWastelandBasic"] = pygame.image.load(os.path.join(WastelandSprites + "\WastelandBasic.png")).convert_alpha()
    Sprites["TileWastelandBasic"] = pygame.transform.scale(Sprites["TileWastelandBasic"], (50, 50)).convert_alpha()

    return Sprites

Upvotes: 0

Views: 529

Answers (1)

jangler
jangler

Reputation: 987

The problem is not because of your dictionary. The signature of blit is

blit(source, dest, area=None, special_flags = 0) -> Rect

where source must be a surface. However, this assumes that blit is being invoked with a pygame.Surface instance as the receiver. Instead, you're calling the blit function from its class, which means that its signature is effectively

blit(self, source, dest, area=None, special_flags = 0) -> Rect

where self must also be a surface. You could fix your problem by changing the call to

pygame.Surface.blit(screen, Sprites["TileWastelandBasic"], (0, 0))

but I would recommend the more idiomatic

screen.blit(Sprites["TimeWastelandBasic"], (0, 0))

instead.

See: http://www.pygame.org/docs/ref/surface.html#pygame.Surface.blit

Upvotes: 1

Related Questions