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

[pygame] Creating surfaces



This is my first game in Pygame, so I understand if this is something stupid that I'm overlooking.

In my class named Player, I have the following lines (lines 93-99) in the __init__ method which is intended to dynamically create the image used for the player object:

self.sprite = pygame.Surface(size[0]+gunsize[0],max(size[1],gunsize[1])).convert()
pygame.draw.rect(self.sprite, color, ((0,0),size))
pygame.draw.polygon(self.sprite, color, \
                    [(size[0],(size[1]//2)-(gunsize[1]//2)), \
                     (size[0],(size[1]//2)+(gunsize[1]//2)), \
                     (size[0]+gunsize[0],size[1]//2)])
pygame.transform.flip(self.sprite, flip, 0)

To test if this works, I created an instance of class Player to display on the screen here (lines 54-55):

self.p1 = Player(0,0,(100,100),lncolor,0,(8,64),(16,8))
self.sprites.append(self.p1)

The line giving me trouble right now is the first one I listed above:

self.sprite = pygame.Surface(size[0]+gunsize[0],max(size[1],gunsize[1])).convert()

Which results in the following output:

Traceback (most recent call last):
  File "C:\Users\Jaychant\Documents\Games\senso.py", line 111, in <module>
    game = Game((640,480), (0,0,0), (0,200,0))
  File "C:\Users\Jaychant\Documents\Games\senso.py", line 54, in __init__
    self.p1 = Player(0,0,(100,100),lncolor,0,(8,64),(16,8))
  File "C:\Users\Jaychant\Documents\Games\senso.py", line 93, in __init__
    self.sprite = pygame.Surface(size[0]+gunsize[0],max(size[1],gunsize[1])).convert()
ValueError: size needs to be (int width, int height)

Here is what the important variables end up being:
size: (8,64)
gunsize: (16,8)

What I gather from this is that I'm not specifying an integer where I should be. But I've checked the arguments; The first becomes 8+16=24, while the second becomes 64.

Can anyone see what's wrong? Am I misinterpreting the error?

I have attached the entire file to this Email, in case it is needed.

Cheers,
onpon4

Attachment: senso.py
Description: Binary data