1

I have a problem with:

screen.blit(tile, [(x*tilewidth) - CAMERA.x +(WIDTH/2) , (y*tileheight) - CAMERA.y + (HEIGHT/2)])

screen.blit(object.image, [object.x - CAMERA.x +(WIDTH/2), object.y - CAMERA.y + (HEIGHT/2)])

The code above generates an error:

DeprecationWarning: an integer is required (got type float).  Implicit conversion to integers using __int__ is deprecated and may be removed in a future version of Python.
  screen.blit(tile, [(x*tilewidth) - CAMERA.x +(WIDTH/2) , (y*tileheight) - CAMERA.y + (HEIGHT/2)])

The program starts but then crashes due to an error. How do I fix this?

Qiu YU
  • 517
  • 4
  • 20

1 Answers1

3

round the cooridantes to integral values:

screen.blit(tile, [(x*tilewidth) - CAMERA.x +(WIDTH/2) , (y*tileheight) - CAMERA.y + (HEIGHT/2)])

screen.blit(tile, 
    [round(x*tilewidth - CAMERA.x + WIDTH/2), round(y*tileheight - CAMERA.y + HEIGHT/2)])

or use the // (floor division) operator (this only works if all the variables have integral values):

screen.blit(tile, 
    [x*tilewidth - CAMERA.x + WIDTH//2, y*tileheight - CAMERA.y + HEIGHT//2])
Rabbid76
  • 202,892
  • 27
  • 131
  • 174