我正在寻找一种在游戏运行时更改渲染文本的方法。
我发现有人说只需更改文本变量即可。
所以我试试这个:
import arcade
WINDOW = {"width":800, "height": 600, "title": ""}
class MyGame(arcade.Window):
"""
Main application class.
"""
def __init__(self):
# Call the parent class and set up the window
super().__init__(WINDOW['width'], WINDOW['height'], WINDOW['title'])
arcade.set_background_color(arcade.csscolor.CORNFLOWER_BLUE)
def setup(self):
""" Set up the game here. Call this function to restart the game. """
pass
def on_draw(self):
""" Render the screen. """
arcade.start_render()
# Code to draw the screen goes here
self.text = "Hello world!"
arcade.draw_text(self.text, WINDOW['width'] / 3 + (WINDOW['width'] / 3 / 3) - 20, WINDOW['height'] / 2, arcade.csscolor.WHITE, 18)
def on_mouse_release(self, x, y, button, key_modifiers):
print("Clicked!")
self.text = "Clicked!"
def main():
""" Main method """
window = MyGame()
window.setup()
arcade.run()
if __name__ == "__main__":
main()
但是,文本没有改变,但它可以检测到点击。