Best way to set up behaviors?

  • Is there any reason to use one or the other of the two setups in the screen shot?0_1510515851046_87141109-CCA5-4ECC-A0F5-C8EF364638F7.png

  • @iTap-Development As I understand it, for duration based activities, the example on the left will activate actions based on those durations.

    So if you want to:

    • move up 10 metres during 1 second
    • move down 10 metres during 1 second

    If you use the layout on the right, the object won't appear to move to up as that behaviour will be overridden by the immediate call of the move to go down.

  • @Deeeds oh I didn’t even think about that, but I tested and that is the case. With the exception of the interrupt movement toggle being on on the second behavior, in which case the second behavior will run. But the first one won’t run regardless of the toggle being on or off on either.

  • @iTap-Development I think if you use the one on the right it will all happen faster.

  • @Aidan-Oxley why? They look exactly the same?

  • @Jack8680 Theoretically, the one on the right should be able to initiate and issue a bunch of math operations before the results come back. But that depends a lot on what's going on inside cocos2D in terms of managing this sort of rapid fire activity, and how hyperPad lads have done things, too, how iOS plays with it, how many cores you have, etc etc...

    If you were doing this through arrays, and trying to operate on a bunch of things, I'd use the technique on the right just in case you get speed advantages, because that's definitely where you're going to get them.

    The one on the left is going to wait for the result from each math operation before continuing... I think. Probably. That would be the safest way it could be programmed, since subsequent operations for the one on the left might be relying on results further up the branch to operate on.

  • @Deeeds why would you get speed advantages on the right?

  • @Deeeds The behaviours on the right can still use the outputs from previous behaviours though, and they will activate in order. For example replacing 'add values4' with a loop that runs loads of times, the loop will finish before 'divide values2' (next to it) will activate.

    I set up a project to test which runs faster and they seem to be around the same. For a moment the left one seemed slightly faster, but switching the behaviours in the two objects around reversed the result, so it's impossible to tell exactly which is faster, they were both within a few percent of each other, I'm guessing something in the engine itself affects it slightly.

    I'm assuming it compiles the behaviours into 1 dimensional code, and that the two will be identical. When a behaviour has a duration the left one waits for it to finish, while the right one probably performs a step each frame, while still continuing with the behaviours next to it. For multiply, add, divide though, there's no noticeable difference.

  • @Jack8680 so if I added another add values to the right one, would the divide run before the second add values?

  • @Murtaza or @Hamed what way would you recommend?

Log in to reply