尝试运行时接收到类型错误:
File "/home/XX/PycharmProjects/rogue_like/venv/lib64/python3.7/site-packages/tcod/libtcodpy.py", line 1236, in console_put_char
lib.TCOD_console_put_char(_console(con), x, y, _int(c), flag)
TypeError: an integer is required
Class Object:
def __init__(self, x, y, char, color):
self.x = x
self.y = y
self.char = char
self.color = color
def draw(self):
libtcod.console_set_default_foreground(con, self.color)
libtcod.console_put_char(con, self.x, self.y, self.char, libtcod.BKGND_NONE)
# later...
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
player = Object(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, '@', libtcod.yellow)
在一个类似流氓的教程之后,遇到了这个问题。试图通过将“@”改为数字等方式传递整数。试着把它交给
int(self.char)
还有其他的选择,但似乎是碰壁了。
任何帮助都很好!试图包含相关的代码,如果有其他的,请告诉我。
编辑:
"""
...
Args:
con (Console): Any Console instance.
x (int): Character x position from the left.
y (int): Character y position from the top.
c (Union[int, AnyStr]): Character to draw, can be an integer or string.
flag (int): Blending mode to use, defaults to BKGND_DEFAULT.
"""
lib.TCOD_console_put_char(_console(con), x, y, _int(c), flag)