1

我有一个问题:

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)])

上面的代码会产生错误:

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)])

程序启动但随后由于错误而崩溃。我该如何解决?

4

1 回答 1

3

round整数值的坐标:

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)])

或使用//(地板除法)运算符(仅当所有变量都具有整数值时才有效):

screen.blit(tile, 
    [x*tilewidth - CAMERA.x + WIDTH//2, y*tileheight - CAMERA.y + HEIGHT//2])
于 2020-08-14T12:26:02.703 回答