I am trying to assign a separate function to each instance that is created from bgImages, so that when I call instance.collisiontext, it calls that function. I feel like I am doing something wrong. If you look down in the build, you can see an example of where I create an instance and assign a function to collidetext.
The whole point of the collisiontext method is to call the function assigned to collidetext (which is going to be a different function for each instance).
What am I doing wrong here?
Also, when assigning a function to the instance slum, do I need to keep the '()' after 'slumnotice'?
class BgImages(ButtonBehavior, Image):
def __init__(self, **kwargs):
super(Npcs, self).__init__(**kwargs)
self.collidetext=''
def collisiontext(self,**kwargs):
global collidetext
return collidetext()
class MainCharacter(Image):
def __init__(self, **kwargs):
super(MainCharacter, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(None, self)
if not self._keyboard:
return
self._keyboard.bind(on_key_down=self.on_keyboard_down)
self._keyboard.bind(on_key_up=self.on_keyboard_up)
elif keycode[1] == 'up':
for i in listofwidgets:
if i.collide_point(self.x,self.top):
self.y -=1
i.collisiontext()
class gameApp(App):
def build(self):
slum=BgImages(source='slum.png', collidetext=slumnotice())
listofwidgets=[]
listofwidgets.append(slum)