如何解决在pygame blit中绘制浮动
我有一个问题:
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,(y*tileheight) - CAMERA.y + (HEIGHT/2)])
程序启动,但由于错误而崩溃。我该如何解决?
解决方法
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])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。