On Mon, Sep 21, 2009 at 8:14 PM, karan <[email protected]> wrote:
>
> Is there way by which I can ensure that a screen is exited when the
> enter key is pressed? Will I have to code this in the Layer class of
> that scene, or elsewhere? Also, I would like a particular value to be
> saved when the user presses enter and leaves the screen.
>
Well, you can add, in the layer where you are listening to on_key_press a
method
def exit_scene(self):
self.save()
# you have to decide what of the following is better for you:
director.pop() # quit this scene and goes to the one when you called
director.push()
scene = OtherScene(...)
director.replace(scene) # quits the current scene and goes to the
OtherScene instance
scene = OtherScene()
director.push(scene) # suspends the current scene going to to the
OtherScene instance,
# later you can return to the current scene
with director.pop()
def save(self):
# your code to save whatever needs saving
...
Then your on_key_press method should call self.end_scene() when it detects a
return press.
--
claudio
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---