Okay I think I've got it?
When you do something like:
x = ( MoveTo(p, 1) + MoveTo(p2, 1) )
x becomes an instance of Sequence_IntervalAction.
And also:
x = InstantAction()
x += MoveTo(p, 1)
x += MoveTo (p2, 1)
x is also an instance of Sequence_IntervalAction
Taking this into account I also noticed that if I do:
x = InstantAction(MoveTo(p,1))
x becomes an instance of InstantAction and not Sequence_IntervalAction
But as soon as you try to add an action to it, it will become a
Sequence_IntervalAction
and then I understood what you meant, I could have just done:
x = MoveTo(p,1)
x += MoveTo(p2,1)
I would have still gotten a Sequence_IntervalAction. you used InstantAction
because it does absolutely nothing! therefor you used this "empty
container" that would become a Sequence_IntervalAction as soon as you
concatenated actions into.
Your function speaks for itself after I understood this:
def action_follow_checkpoints(self, points):
template_action = InstantAction()
for p in points:
template_action += MoveTo(p, 0.3)
return template_action
By the way,
Regarding the A* algorithm itself, do you know of a more efficient of
pathfinding?
While the algorithm I'm using works very well, it's quite slow when trying
to solve a maze for example, or go long distances, which halts the program
for a few seconds until it's done computing. That makes the sprite jump a
large distance at once..
Also it hits a recursion limit when the distance is too high. so I have to
raise it with:
sys.setrecursionlimit(1500)
Which is just a bummer.
Maybe someone else did pathfinding more efficiently already?
On Sunday, 29 November 2015 21:13:22 UTC+2, Claudio Canepa wrote:
>
>
>
> On Sun, Nov 29, 2015 at 11:15 AM, Netanel M. <[email protected]
> <javascript:>> wrote:
>
>> Wow, thank you so much, that worked perfectly.
>>
>
> ...
>
>
>> You used the InstantAction class from cocos.actions.base_actions.
>> But you treated it as a template, concatenating other actions into it
>> using the sequence operator "+".
>> But I hadn't thought of InstantAction and IntervalAction as containers
>> but as bases for independent actions like "MoveTo"
>>
>>
> Ummm... maybe you are distracted by incidental aspects ?
> Just to clarify,
>
> - To 'add many' in a loop, I needed an accumulator (so I can write
> acc += element )
> - An initial value of DoNothing action for the accumulator seems adequate
> - Incidentally, InstantAction behaves as a DoNothing, so lets use it.
>
> - I used the varname template_action in the same sense as used in the
> cocos docs, which wants to distinguish two distinct roles for Action
> instances:
>
> worker_action = cocosnode.do(template_action)
>
> worker_action is a copy of template_action; it's step method will be
> called to perform the desired changes
> template_action holds the complete description of desired changes.
>
> Why not let template_action perform directly the changes ?
> To allow things like
> template_action = MoveTo((100, 100), 2)
> blue_monster.do(template_action)
> sleep(2)
> red_monster.do(template_action)
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/d/optout.