when i run this i get the error "TypeError: argument 1 must be pygame.Surface, not pygame.Rect" which many people seem to get from using circles and stuff but I'm not using any rects or circles in this code at all. so I'm not sure where the rect is coming from. not seen a duplicate of this where they have only used surfaces either.
note that this code requires a png called "missing.png" in the directory its in - can be anything doesn't matter what it actually is.
import pygame
from sys import exit
pygame.init()
screenwidth = 1000
screenheight = 500
fps = 32
screen = pygame.display.set_mode((screenwidth,screenheight))
clock = pygame.time.Clock()
class sprite():
def __init__(self,
position = (0,0),#top left
frames = 1,
finalsize = (100,100),
pngname="missing.png",
startingframe = 1):
self.position = position
self.frames = frames
self.finalsize = finalsize
self.pngname = pngname
self.currentframe = startingframe
self.immage = pygame.image.load(self.pngname)
#dimentions defined, self.framesurface
#transparency
totalwidth = self.immage.get_width()
self.frameheight = self.immage.get_height()
self.framewidth = totalwidth/self.frames
self.framesurface = pygame.Surface((self.framewidth,self.frameheight))#makes surface with frame dimentions
self.framesurface.convert_alpha()
self.framesurface.fill((0,0,0,0))
clear_surface = pygame.Surface((totalwidth,self.frameheight))
clear_surface = clear_surface.convert_alpha()
clear_surface.fill((0,0,0,0))#transparent surface made
self.immage = clear_surface.blit(self.immage,(0,0),(0,0,finalsize[0],finalsize[1]))
#self.immage
#self.framesurface
def frame_render(self):
self.immage = self.framesurface.blit(self.immage,#error happening on this line
(0,0),
(0, self.framewidth*self.currentframe, self.framewidth, self.frameheight)) #blits one frame
self.immage = pygame.transform.scale(self.immage,self.finalsize)#scales immage to finalsize
self.immage = screen.blit(self.immage,self.position,(0,0,self.framewidth,self.frameheight))
test = sprite()
while True:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
screen.fill((255,255,255))
test.frame_render()
pygame.display.update()