python - Pygame convert surface into sprite -


i want make game cards, heartstone, lot simplier (coz not pro programmer). part of program

import pygame  class card: def adcard(self, adcard):     self.adcard = adcard def hpcard(self, hpcard):     self.hpcard = hpcard def picture(self, picture):     self.picture = picture def special(self, special):     if special == "heal":         pass  pygame.init() display = pygame.display.set_mode((0, 0), pygame.fullscreen)   swordsman = card() swordsman_picture = pygame.image.load("swordsman.png").convert() swordsman.picture(swordsman_picture) print(type(swordsman.picture)) 

now problem prints type of picture class 'pygame.surface' want picture sprite. how that. tnx.

sprite class use surface keep image , rect keep positon , size.

class card(pygame.sprite.sprite):      def __init__(self, surface):         pygame.sprite.sprite.__init__(self)          self.image = surface          self.rect = self.image.get_rect() # size , position  # ,  one_card = card(swordsman_picture) 

(see pygame documentation: pygame.sprite.sprite )

or did't see before

one_card = pygame.sprite.sprite() one_card.image = swordsman_picture one_card.rect = one_card.image.get_rect() # size , position 

btw: use "camelcase" names classes names - make code more readable - stackoveflor editor treads picture, adcard, etc class name , use blue color. functions , variables use lower_case names.


this seems useless

def picture(self, picture):     self.picture = picture  swordsman.picture(swordsman_picture) 

you can same in 1 line - , make more readable.

swordsman.picture = swordsman_picture 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -