This error occurs because the method getAverageFrameRate() is not defined in the MyApp class. To fix it, we can add the method to the class:

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase): def init(self): ShowBase.init(self) self.accept("escape", self.quit) self.taskMgr.add(self.printFrameRate, "printFrameRateTask")

def printFrameRate(self, task):
    frameRate = self.getAverageFrameRate()
    print("Frame rate: {0:.2f} fps".format(frameRate))
    return task.cont

def quit(self):
    self.userExit()

def getAverageFrameRate(self):
    return globalClock.getAverageFrameRate()

app = MyApp() app.run()

In this updated version of the code, the getAverageFrameRate() method is defined in the MyApp class, and simply returns the value of globalClock.getAverageFrameRate(). This should resolve the AttributeError and allow the program to run as expected

from directshowbaseShowBase import ShowBaseclass MyAppShowBase def __init__self ShowBase__init__self selfacceptescape selfquit selftaskMgraddselfprintFrameRate printFrameRateTa

原文地址: https://www.cveoy.top/t/topic/hsK6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录