python - Pygame: Showing sprite without a group -


i have 2 sprites in class easier control (specifically: tank turret , suspension). if try launch program works without errors, doesn’t show anything. tried put both of sprites in group in class, threw error

typeerror: draw() missing 1 required positional argument: 'surface' 

the code is:

class bokstelis(pygame.sprite.sprite):     def __init__(self,atvaizdas,centerx,centery,sukgreitis):         pygame.sprite.sprite.__init__(self)         self.nuotr=pygame.image.load(atvaizdas)         self.image=self.nuotr         self.rect=self.image.get_rect()         self.rect.centerx=centerx         self.rect.centery=centery         self.sukgreitis=sukgreitis         self.kryptis=0     def update(self):         mousex, mousey=pygame.mouse.get_pos()         self.angle = math.degrees(math.atan2(mousey - self.rect.centery, mousex - self.rect.centerx))         orig_rect=self.rect         if self.angle - self.kryptis <self.sukgreitis:             self.image=pygame.transform.rotate(self.nuotr,-(self.sukgreitis+self.kryptis))         elif self.angle - self.kryptis >self.sukgreitis:             self.image=pygame.transform.rotate(self.nuotr,self.sukgreitis+self.kryptis)         else:             self.image=pygame.transform.rotate(self.nuotr,-angle)         self.rect=self.image.get_rect()         self.rect.center=orig_rect.center         self.kryptis=self.angle class pagrindas(pygame.sprite.sprite):     def __init__(self,atvaizdas,centerx,centery,sukgreitis):         pygame.sprite.sprite.__init__(self)         self.nuotr=pygame.image.load(atvaizdas)         self.image=self.nuotr         self.rect=self.image.get_rect()         self.rect.centerx=centerx         self.rect.centery=centery         self.sukgreitis=-sukgreitis         self.kryptis=0     def suktis(self):         orig_rect=self.rect         self.image=pygame.transform.rotate(self.nuotr,-sukgreitis)         self.rect=self.image.get_rect()         self.rect.center=orig_rect.center         self.kryptis-=kryptis class tankas:     def __init__(self,centerx,centery,bokstelis,pagrindas,maxjudgreit,galingumas,svoris):         self.bokstelis=bokstelis         self.pagrindas=pagrindas         self.centerx=centerx         self.centery=centery         self.bokstelis.rect.center=(self.centerx,self.centery)         self.pagrindas.rect.center=(self.centerx,self.centery)         self.grup=pygame.sprite.group(self.bokstelis,self.pagrindas)         self.maxjudgreit=maxjudgreit         self.galing=galingumas         self.svoris=svoris         self.judejimas=0         self.kryptis=self.pagrindas.kryptis         self.greit=false         self.maxdabgreit=72     def update(self):         self.centerx,selfcentery=self.judejimas * math.cos(math.radians(self.kryptis)), self.judejimas * math.sin(math.radians(self.kryptis))         self.bokstelis.rect.center=(self.centerx,self.centery)         self.pagrindas.rect.center=(self.centerx,self.centery)         self.bokstelis.update()         self.pagrindas.update()         if self.maxdabgreit < self.judejimas:             selfjudėjimas-=self.galing/self.svoris         elif self.greit:             self.judejimas=self.judejimasself.galing/self.svoris 

for adding class added 'self.grup(self.bokstelis,self.pagrindas)' in __init__, , changed self.bokstelis.update() , self.pagrindas.update() with

self.grup.clear() self.grup.update() self.grup.draw() 

full eror mesage:

traceback (most recent call last):   file "c:\users\kiela\dropbox\ik8\ik3\world of tankz.py", line 76, in <module>     tankas.grup.draw() typeerror: draw() missing 1 required positional argument: 'surface' 

what should displaying of tank without disabling of class?

pygame.sprite.group.draw() requires non optional argument 'surface'. if you're bliting straight screen (screen = pygame.display.set_mode()) do: self.grup.draw(screen) other alternative make surface , blit screen:

screen = pygame.display.set_mode((0, 0)) # create main window #create sprites , groups etc. ...  surface = pygame.surface(screen.get_size) self.grup.draw(surface) screen.blit(surface) pygame.display.flip() 

but more complicated of two. if want straight docs can found here: https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.group.draw


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -