Reputation: 65
I've been working on a tiled map renderer, and I've tried to make a seperate Class in another file. I get this error message:
Type Error: 'renderer' object is not callable
Here's the render.py file:
import pyglet, json
from pyglet.window import key
from pyglet.gl import *
from ConfigParser import SafeConfigParser
from cocos.layer import *
from cocos.batch import *
from cocos.sprite import Sprite
class renderer( Layer ):
def __init__(self, mapname):
super( renderer, self ).__init__()
parser = SafeConfigParser()
try:
world = parser.read('maps/'+mapname+'.txt')
print world
except IOError:
print("No world file!")
return
layer = json.loads(parser.get('layer1', 'map'))
tiletype = parser.get('type', 'tile')
print tiletype
tilesize = 64
for x in range(0, len(layer)):
for y in range(0, len(layer[x])):
self.spr = Sprite("image/tiles/"+tiletype+"/"+str(layer[x][y])+".png")
self.spr.position = ((x+1)*tilesize, (y+1)*tilesize)
self.add(self.spr)
And this is the piece of code I call it with:
from other.render import renderer
world = renderer('buildnew')
world()
File Structure:
game/main.py
game/other/render.py
What am I doing wrong?
Upvotes: 0
Views: 538
Reputation: 4267
world = renderer('buildnew')
world()
First you make an instance of the renderer class and store it to world.
But then you write world()
, which is wrong cause this object is not callable.
If you want to make world
a callable object, you should implement the __call__
method in the renderer class.
Upvotes: 0