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.

Fixing 'AttributeError: 'MyApp' object has no attribute 'getAverageFrameRate'' in Python

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

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