On Sat, Apr 25, 2009 at 11:36 AM, Facundo Batista
<[email protected]> wrote:
>
> Started coding cocos2d myself, one of the first things I got stuck is
> sheduling function calls to the future.


i usually do: self.do( Delay(delta) + CallFunc(function) )

>
> I searched for a callLater method in the layers (à la twisted), but
> didn't found it. No problem, I thought, I always can schedule a
> function to the future, and then unschedule the function inside
> itself.
>
> Something like
>
> """
>    ...
>    self.schedule(self.func, delta_time)
>
> def func(self, delta_time):
>    self.unschedule(self.func)
> """
>
> But, this broke my code, in the following situation: I had a lot of
> sprites, and during some analysis, I do an action on some, and then
> schedule for later some logic. The problem is that I schedule "func"
> several times, but the first time "func" is called, it unschedule
> itself, so it's only called *once*.

The use of timers is specially good for static things, that you will
most likely need one function doing the updating. So its good to be
able to remove that function from anywhere else.

>
> I quickly fixed this issue creating a "call_later" method:
>
> """
>    def call_later(self, dt, func, *args, **kwargs):
>        def f(dt, args, kwargs):
>            self.unschedule(f)
>            func(*args, **kwargs)
>        self.schedule_interval(f, dt, args, kwargs)
> """
>
> The question is... does this exist and I didn't find it? if not, why
> doesn't it exist? Is not usefule normally?

i always do the action stuff. But this is not a bad idea. The problem
is that it will work differently than the other scheduling funcions,
so im not sure it will be clear. And if you want to cancel the call,
how do you do it? we need yet another registry of stuff.

>
> Furthermore, it could be useful a more-like-gtk schedule function [0],
> that keeps calling the function until it returns False.

If the update functions know when they should unschedule themselves,
you start to get logic spread all over the place.  Its a good thing to
be able to remove them from somewhere else.

>
> What do you think about this?
>

my2c.
Lucio.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

  • Call later Facundo Batista
    • Re: Call later Lucio Torre

Reply via email to