[英]Using more than one class
Im writing a pygame and so far i have 2 classes 我写了一个pygame,到目前为止,我有2个班级
one that is the Main class a 一个是主类a
and another that is used to draw images for later in the game 另一个用于在游戏中稍后绘制图像
im trying to call the drawing part from the Main class 我试图从Main类调用绘图部分
i got it to work fine the problem is i need to run the Draw classes __init__
just once instead of looping it 我得到它工作正常问题是我需要只运行一次Draw类
__init__
而不是循环它
here is where i call it: 这是我称之为的地方:
if self.state == 2:
if pygame.time.get_ticks() - self.last_tick > 40:
Draw().update(screen)
it works but there are variables in the init of the Draw
class that need to be defined once instead of over and over again in the game loop 它有效,但
Draw
类的init中有一些变量需要在游戏循环中一次又一次地定义而不是一遍又一遍
so how can i call this class so that the __init__
runs but doesn't loop? 那么如何调用这个类以便
__init__
运行但不循环?
here is a link to the Draw
class: 这是
Draw
类的链接:
thanks for reading all that if you can help please do! 感谢阅读所有这些,如果你可以帮助请做!
Can't you just do something like this: 你不能只做这样的事情:
the_class = Draw()
while looping:
the_class.update()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.