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

Re: [pygame] Image error



Samuel Mankins schrieb:
When I try to load a .png image, it gives me this error:

Traceback (most recent call last):
File "/Users/samuelmankins/Desktop/PvsN/alpha/PvsN.py", line 270, in ?
MainWindow.MainLoop()
File "/Users/samuelmankins/Desktop/PvsN/alpha/PvsN.py", line 32, in MainLoop
self.LoadSprites();
File "/Users/samuelmankins/Desktop/PvsN/alpha/PvsN.py", line 208, in LoadSprites
self.sword = ninjaWeapon(6, 4, 2, 0, img, img2)
File "/Users/samuelmankins/Desktop/PvsN/alpha/weaponSprites.py", line 33, in __init__
self.image_trans = pygame.transform.rotate(self.image_call, 0)
TypeError: argument 1 must be pygame.Surface, not tuple
samuel-mankins-ibook-g4:~/Desktop/PvsN/alpha samuelmankins$


The thing is, this particular weapon Sprite has two images, so it can be "animated", and when it only had one, it worked just fine. There's also another, of the exact same class, that just loads the same image twice and works just fine. All the images involved are .pngs, and the working sprite is loaded before this one.
The code that loads the sprite and feeds it the images:


   img = load_image('sword-1.png',-1)
   img2 = img_list[self.level.SWORD]
   self.sword = ninjaWeapon(6, 4, 2, 0, img, img2)

The class startup and init function:

class ninjaWeapon(pygame.sprite.Sprite):

   def __init__(self, dist, moves, dam, stop, image, image2):

      pygame.sprite.Sprite.__init__(self)
      self.dist = dist
      self.moves = moves
      self.moveCount = 0;
          self.dir = 0  # 1 = right, 2 = left, 3 = up, 4 = down
          self.xMove = 0
          self.yMove = 0
          self.thrown = 0
          self.dam = dam
          self.stop = stop
          self.frame_count = 0
          self.image_a = image
          self.image_b = image2
          self.image_call = self.image_a
          self.image_trans = pygame.transform.rotate(self.image_call, 0)
          self.image = self.image_trans

And the code that changes the sprites image depending on what direction it's facing in:

   def place(self, key):

if (key == K_RIGHT):
self.dir = 1
self.image_trans = pygame.transform.rotate(self.image_call, 180)
elif (key == K_LEFT):
self.dir = 2
self.image_trans = pygame.transform.rotate(self.image_call, 0)
elif (key == K_UP):
self.dir = 3
self.image_trans = pygame.transform.rotate(self.image_call, 270)
elif (key == K_DOWN):
self.dir = 4
self.image_trans = pygame.transform.rotate(self.image_call, 90)


          self.image = self.image_trans

At the moment, there isn't any code that switches the sprite's images back and forth, but I just want to get it to load properly first. These sections of code are not all that's there, but there's enough in the source file that I think it would be silly to copy and paste all of it.
Is there any obvious problem here? Would it be somewhere else, in something I didn't put in? If not, thanks anyway, I can keep trying to figure it out on my own.


--Skizzaltix


Hi

img = load_image('sword-1.png',-1)

sure that returns a Surface and not a tuple?

because in your traceback:

File "/Users/samuelmankins/Desktop/PvsN/alpha/weaponSprites.py", line 33, in __init__
self.image_trans = pygame.transform.rotate(self.image_call, 0)
TypeError: argument 1 must be pygame.Surface, not tuple


It seem that you pass a tuple to rotation.

~DR0ID