CCCallFuncN usage

I have just finished watching the guest lecture "Introduction to CocosSharp". I'm now going over the sample code included with the lecture.

At the top of the GameLayer class is the following declaration:

CCCallFuncN removeNodeAction = new CCCallFuncN (node => node.RemoveFromParent ());

My understanding is that removeNodeAction is being passed a node object and then calling the node's RemoveFromParent method and that the code will be executed immediately.

Further down in the example is the following method

    void Fire ()
        var shot = new CCDrawNode ();

        shot.DrawCircle (new CCPoint (0, 0), SHOT_RADIUS, CCColor4B.Red);
        shots.AddChild (shot); 
        shot.Position = new CCPoint (ship.Position.X + 60.0f, ship.Position.Y - 2.5f);

        var moveShot = new CCMoveTo (1.0f, new CCPoint (VisibleBoundsWorldspace.MaxX, shot.Position.Y));
        shot.RunActions (moveShot, removeNodeAction);

If I'm reading this correctly, the method creates a new CCDrawNode called shot. We then call DrawCircle at the specified point with the specified color. We add the shot object as a child to the previously defined shots node. We give the shot a specific position relative to the ship object. We then set up a moveShot variable of type CCMoveTo that specifies the duration and location the shot is to move towards.

Finally, the shot's RunAction method is called. This is where I'm unclear of what is going on.

My understanding is that RunActions takes a series of actions and runs them one after another I can understand passing the moveShot variable to this method, since we want the app to move the shot along the pre-defined trajectory. What I don't understand is why the next action we want to run is removeNodeAction. Why do we want to delete the shot right after we have created it? What am I missing here? I think I don't fully understand using CCCallFuncN and the documentation is sparse.

Best Answer


  • JaredMathesJaredMathes CAUniversity

    Thanks Michael for the explanation!

Sign In or Register to comment.