ScenePop and SceneReplace Actions

27 views
Skip to first unread message

Oninoshiko

unread,
Apr 9, 2012, 4:21:14 AM4/9/12
to cocos2d discuss
I'm putting together a pair of InstantActions to solve the problem
where you want to change Scenes after the action completes. I'm
calling the ScenePop and SceneReplace.

ScenePop works like a charm.

SceneReplace, on the other hand, does not. It thows an error about a
deepcopy failing when I try to pass in the scene I want to replace the
current one with. Honestly, I'm not sure why it would need a deep copy
in this case rather then just passing a reference (is there a way to
force that behavior?),

I'm using Cocos2d 0.5 and Python 2.6.6

claudio canepa

unread,
Apr 9, 2012, 4:54:36 AM4/9/12
to cocos-...@googlegroups.com

--

It is a limitation in current design. They are some workaounds, like store the reference in the action target, or pass the reference you want not deepcopied as an action.init2 method to be called as in
template_action = MyAction()
worker_action = node.do(template_action)
worker_action.init2( param_to_not_deepcopy)

The last workaround can be seen in the test\test_action_non_interval.py example.

I you show code maybe a more specific workaround can be sugested.

--
claudio
 

Oninoshiko

unread,
Apr 9, 2012, 11:38:58 AM4/9/12
to cocos-...@googlegroups.com

Of course! What I have is this:

 class ReplaceScene(InstantAction):
    def init(self, newscene):
        self.newscene = newscene

    def start(self):
        director.replace(self.newscene)
 Ideally, I just want to be able to add "ReplaceAction(Scene(layer))" to the end of a Action sequence.

claudio canepa

unread,
Apr 9, 2012, 12:58:51 PM4/9/12
to cocos-...@googlegroups.com
On Mon, Apr 9, 2012 at 12:38 PM, Oninoshiko <onino...@gmail.com> wrote:


Of course! What I have is this:

 class ReplaceScene(InstantAction):
    def init(self, newscene):
        self.newscene = newscene

    def start(self):
        director.replace(self.newscene)
 Ideally, I just want to be able to add "ReplaceAction(Scene(layer))" to the end of a Action sequence.
--

I see.
A clean way to obtain an action with this behavior is this:

def get_action_replace_scene(scene):
      def changer():
          director.replace(scene)

      template_action = ac.CallFunc(changer)
      return template_action

and you use like

template_action = ac.Delay(1.0) + get_action_replace_scene(scene2)
scene1.do(template_action)
director.run(scene1)
See test demo for this in http://pastebin.com/xVW3WYJW


claudio

--

Oninoshiko

unread,
Apr 9, 2012, 5:13:53 PM4/9/12
to cocos-...@googlegroups.com

That worked great. Here is what I ended up with, all three seem to work fine. If this is something that would be desired in a later release, feel free to use this with me blessing!
SceneAction.py

claudio canepa

unread,
Apr 10, 2012, 10:44:12 PM4/10/12
to cocos-...@googlegroups.com
On Mon, Apr 9, 2012 at 6:13 PM, Oninoshiko <onino...@gmail.com> wrote:



That worked great. Here is what I ended up with, all three seem to work fine. If this is something that would be desired in a later release, feel free to use this with me blessing!
--
 

Looks clean and very legible.
I can add them in a programming guide recipe

--
claudio


 
Reply all
Reply to author
Forward
0 new messages