On Mon, Feb 17, 2014 at 2:35 PM, Robinson Risquez <[email protected]>wrote:
> If you want to access in __init__ the only way would be to pass a
>> reference to gameplay layer, but that looks clunky.
>>
>> Probably I would prefer to make a property of Player like
>>
>> class Player(cocos.sprite.Sprite):
>> ...
>> def on_enter(self):
>> self._gameplay_layer = self.get_ancestor(Gameplay)
>>
>> def _set_score(self, value):
>> self._gameplay_layer.score = value
>>
>> def _get_score(self):
>> return self._gameplay_layer
>>
>> score = property(self._get_score, self._set_score)
>>
>> *I'm trying to do what you say but apparently the "on_enter" method stops
> the function "update" that's in self.schedule(self.update) in the player
> sprite, that is, when I place the method on_enter, the function "update"
> stops updating in each frame. *
> --
>
>
Oh, sorry, i forgot to call super.
Try with
def on_enter(self):
self._gameplay_layer = self.get_ancestor(Gameplay)
super(Player, self).on_enter()
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.