简体   繁体   English

使用多个班级

[英]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类的链接:

The Draw Class 抽奖类

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.

相关问题 使用深度学习对不止一个 class 进行特征提取 - Feature extraction using deep learning for more than one class 一个以上的构造函数 python class - more than one constructor in a python class 在Cherrypy中运行多个类 - Running more than one class in Cherrypy ReadOnly行用于多个具有类的QTableWidget,并获得更高的效率 - ReadOnly row for more than one QTableWidget with class and get more efficiency 如何使用 BeautifulSoup 从属于多个 class 的网站中抓取元素 - How to scrape an element from a website which belongs to more than one class using BeautifulSoup 尝试移动一个对象并将Tkinter用作GUI,但是当类的实例多于一个时,它不起作用 - Trying to move an object and using Tkinter as a GUI, but it is not working when there is more than one instance of the class python使用response.css抓取具有多个类名的div - python scrape a div with more than one class name using response.css 如何在for循环中使用nuke.allNodes()遍历一个以上的nuke节点类? - How to iterate through more than one nuke node class using nuke.allNodes() in a for loop? 使用Brython代码进行多次计算 - Using Brython code with more than one calculation 使用具有多个 dataframe 的 mplcursors - Using mplcursors with more than one dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM