This project is read-only.

Correct usage of CCCallFuncN for Windows 8 XAML app?

Topics: Actions and Control Logic, Windows Phone 8
Jul 19, 2013 at 9:17 PM
Putting together several "how to" examples for Windows 8 devs over the course of creating an app, but not having any luck with action callbacks in C#.

Given the following action:
CCAction moveRight = new CCMoveBy(3, new CCPoint(200, 0));

How do I create a callback using CCCallFuncN? I see examples in iOS, C++, and Java, but they don't seem to port over to C#'s CCCallFuncN.

iOS: id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];

Java: CCCallFuncN actionMoveDone = CCCallFuncN.action(this, "spriteMoveFinished");

Thanks,
Jeff
Jul 19, 2013 at 9:42 PM
RunAction(new CCCallFuncN(() => {
// dance the jig
}));



RunAction(new CCCallFuncNO((o) => {
// dance the jig with o
}));


or you can be explicit

RunAction(new CCCallFuncN(new Action(delegate {
// dance the jig
})));
Jul 19, 2013 at 10:33 PM
Sorry for the followup, but I'm not seeing the results I was expecting - I may not have clearly explained the issue I'm having.

If I want to use the following code to call a method "test" after the animation "backAndForth" completes, how is that formed?

RunAction(new CCCallFuncN(() => {
// dance the jig
}));

Trying the following plays the animation, but doesn't call the method "test" when the animation has completed:

whichSystem.RunAction(new CCCallFuncN((test) =>
{
// dance the jig
whichSystem.RunAction(backAndForth);
}));

Thanks,
Jeff
Jul 19, 2013 at 10:45 PM
new CCSequence(backAndForth, new CCCallFuncN(()=> {
CCLog.Log("I AM HERE NOW!");
}));
Jul 19, 2013 at 10:50 PM
Edited Jul 19, 2013 at 10:50 PM
Another example of a more complicated sequence that you can only do in cocos2d-xna:
      HelpPullTabRight.RunAction(new CCSequence(
     new CCHide(),
     new CCDelayTime(1.5f),
     new CCShow(),
     new CCRepeatForever(
       new CCSequence( 
       new CCFadeIn(2),
       new CCFadeOut(1.5f)
     ))));
That one waits to show some help graphic, and it pulses it indefinitely.
Jul 19, 2013 at 11:13 PM
Thanks for the examples - the second one works, though only appeared to pulse once (I did not test it thoroughly, just slapped it on the particle system with which I was working).

The first one, which is what I think I am looking for, is reporting two errors (the code editor is underlining the left paren inside the CCCallFuncN:
                                                                                 \/
        new CCSequence(backAndForth, new CCCallFuncN(() =>
        {
            CCLog.Log("I AM HERE NOW!");
        }));
Error 1 Delegate 'System.Action<Cocos2D.CCNode>' does not take 0 arguments
Error 2 Cannot convert lambda expression to type 'Cocos2D.CCCallFuncN' because it is not a delegate type
Jul 19, 2013 at 11:20 PM
 new CCSequence(backAndForth, new CCCallFuncN((o)=> { 
    CCLog.Log("I AM HERE NOW!"); 
  }));
Jul 19, 2013 at 11:40 PM
Exactly what I was looking for - thanks for the help.

Hey, off topic, but any plans to do a Windows Phone XAML version? I've seen the C++ one, but I like the XAML interop (and the C#).

Thanks,
Jeff
Jul 20, 2013 at 12:06 AM
cocos2d-xna\TestWin8Phone

You mean that?