periodically update contents created by CCRenderTexture and CCDrawNode

Topics: Actions and Control Logic, Animation, Compatibility, Sample Code and Demos, Sprites and SpriteBatch
Jan 1, 2014 at 6:32 AM
Edited Jan 1, 2014 at 6:34 AM
tried using CCSchedule to periodically invoke a method which contains the drawing logic, but failed(show nothing). any idea? thanks
Coordinator
Jan 1, 2014 at 7:21 PM
CCScene scene = new CCScene();

scene.RunAction(new CCCallFunc(()=> {
runMyMethod();
{});

That would call it one time. now if you need to periodically call a method, then I suggest you schedule the update method for your node.

Otherwise, if you wanted to schedule a method at a specific time interval on your layer or scene, then do the following:

CCScene scene = new CCScene();

float myTimeoutInSeconds = 1f / 30f; // 30 frames per second for updates
scene.Schedule(myMethod, myTimeoutInseconds);

float elapsedTime = 0f;

public void myMethod(float dt) {
// dt is the time step, not the elapsed time
elapsedTime += dt;
}

This all works. we do this in Santa shooter to handle the collision detection when the avatars throw snowballs.
Coordinator
Jan 1, 2014 at 7:22 PM
If you are looking for a global update then use the main game Update(..) method that exists in your AppDelegate. That gets called with ever draw.
Jan 1, 2014 at 10:42 PM
@totallyevil thanks, i'm trying with your adviced approach
Jan 5, 2014 at 12:53 PM
Edited Jan 5, 2014 at 12:54 PM
@totallyevil, it's ok with your method. And is there any way to remove/hide the drawing dot by dot gradually after the draw (I'm using the CCDrawNode.DrawDot())??
thanks.
Coordinator
Jan 6, 2014 at 2:00 AM
Yes, node.Visible = false will hide the primitive drawing.

The CCDrawNode is just another node.
Jan 6, 2014 at 2:35 AM
@totallyevil thanks.

I drew these dots by the exact same one CCDrawNode instance,
and how to gradually remove/hide/transparent these dots one by one? thanks
Coordinator
Jan 6, 2014 at 3:27 AM
CCDrawNode node1 = new CCdrawNode();
CCDrawNode node2 = new CCdrawNode();

node1.DoSomeDrawing();
node2.DoSomeDrawing();

RunAction(new CCParallel(new CCTargetedAction(node2, new CCRepeatForever(new CCFadeIn(0.23), new CCFadeOut(0.23))), new CCTargetedAction(node1, new CCRepeatForever(new CCFadeIn(0.23), new CCFadeOut(0.23))));

Now they fade in and out forever ... in unison.
Jan 6, 2014 at 3:38 AM
Edited Jan 6, 2014 at 3:39 AM
thanks.

Do I need to use more than two CCDrawNode instances to draw dots, and then make them disappear one by one?
It seems that I draw lots of dot, and use one CCDrawNode instance for each dot cost lots of resources.

Is it possible to use only one CCDrawNode instance to achieve that?
I mean these dots are drawn once by only one CCDrawNode instance in one CCRenderTexture process.
Coordinator
Jan 6, 2014 at 4:57 AM
You could draw the dots into textures, and then use sprites to draw the textures. Then you can apply CCAction instances to the sprites that contain the textures (dots).

On resume, though, you will need to recreate the dot textures.