I am programming a game that's basically using sprites, I was using a sprite sheet for this code and ended up getting the
"invalid destination for blit"
error.
class spritesheet:
def __init__(self, filename, cols, rows):
self.sheet = pygame.image.load(filename).convert_alpha()
self.cols = cols
self.rows = rows
self.totalCellCount = cols * rows
self.rect = self.sheet.get_rect()
w = self.cellWidth = self.rect.width / cols
h = self.cellHeight = self.rect.height / rows
hw, hh = self.cellCenter = (w / 2, h / 2)
self.cells = list([(index % cols * w, index / cols * h, w, h) for index in range(self.totalCellCount)])
self.handle = list([
(0,0), (-hw, 0), (-w, 0),
(0, -hh), (-hw, -hh), (-w, -hh),
(0, -h), (-hw, -h), (-w, -h),])
def draw(self, surface, cellIndex, x, y, handle = 0):
surface.blit(self.sheet, (x + self.handle[handle][0], y + self.handle[handle][1], self.cells[cellIndex]))
s = spritesheet('Number18.png', 6, 58)
CENTER_HANDLE = 4
Index = 0
#mainloop
run = True
while run:
s.draw(DS, Index % s.totalCellCount, HW, HH, CENTER_HANDLE)
Index +=1
pygame.draw.circle(DS, WHITE, (HW, HW), 2, 0)
pygame.display.update()
CLOCK.tick(FPS)
DS.fill(BLACK)
This is basically my whole code and I'm getting a problem on the line
surface.blit(self.sheet, (x + self.handle[handle][0], y + self.handle[handle][1], self.cells[cellIndex]))
constantly giving out the error that this is an invalid destination position for the blit
, i've also noticed that my index has an effect on it too but i don't know what to do.
See Question&Answers more detail:
os