[英]How does ursina engine detect if the update function is declared?
我一直在尝试通过定义来模拟 Ursina 游戏引擎的更新方法
main_game.py
from testengine import *
def update():
pass
def draw():
pass
game = game(900, 500, 'Game', 60)
game.run()
__init__.py
import pygame
class game():
WIN = None
run = False
def __init__(self, WIDTH, HEIGHT, TITLE, FPS):
self.WIDTH = WIDTH
self.HEIGHT = HEIGHT
self.TITLE = TITLE
self.FPS = FPS
WIN = pygame.display.set_mode((self.WIDTH, self.HEIGHT))
pygame.display.set_caption(TITLE)
def run(self):
run = True
clock = pygame.time.Clock()
global update, draw
while run:
clock.tick(self.FPS)
update()
draw()
我尝试导入main_game.py
但它变成了循环导入。
用这个:
try:
update
except NameError:
print("the function update() doesn't exist")
else:
print("the function update exist")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.