xml psuedo code tween and crossfade

  • Hi...

    I'm having a bit of trouble with the code in the xml.

    I've made an interface consisting of floorplans in a building that I want to turn on and off depending on which floor you're at.
    All works fine when I just set the visibility but I really want to do a simple crossfade between two layers.

    I've made an action called 'switchlevel' which in turn calls an action called 'showlevel' twice, once to hide the current floorplan and once to show the new floorplan.

    For the fade I use the tween function but somehow the second time I call 'showlevel' the first tween is simply overridden.

    Here is a simplified version of the action:

    Hope anyone can figure this out, caus I'm stumped *smile*

  • Nicely written code :)

    Uhm the only thing I can think of, is that sLayer isn't set propery (thus he does the same animation twice on the same, which would result in 1 ondone call)
    sLayer being: get(level[%1].val

    probally level is an object you made yourself?

    what happens if you remove the tween and just put alpha = 0 (or 1)? What if you put the tween ondone action in a seperate action instead of inline?

  • Heh thanks... (it's my job though, I better write nice code :-p

    But I'm positive sLayer is set. I can toggle between fading and toggling visibility with that third parameter, and the latter works fine. It's actually no big deal if I don't get the crossfade working, but it's a nice touch.

    Created an extra action instead of inline but it doesn't help. It's weird, code like this would easily work in as3 or js. Unless there's something weird with that tween function, maybe there can be only one?

    I'll go test that right now...

    Think I got the problem...

    You can do multiple tweens but tweens onto the same object get overridden. Strangely, if that object is a variable it will also get overridden.

    Code
    set(plugin[map].foo, -300);
    set(plugin[maphide].foo, 400);
    set(asdf,'map');
    tween(plugin[get(asdf)].foo, 132, 0.5, linear,
    	trace('???????tweenTestDone ',plugin[get(asdf)].foo);
    );
    set(asdf,'maphide');
    tween(plugin[get(asdf)].foo, 312, 0.5, linear,
    	trace('!!!!!!!tweenTestDone ',plugin[get(asdf)].foo);
    );


    In this code only the last callback is traced even though 'plugin[get(asdf)]' is different from the 'plugin[get(asdf)]' in the first tween. So tween checks the literal string value of the first parameter, not the actual object it represents. Nice bug, I wonder if it does the same in the actionscript version (I only need krpano js version for this project).

    Good to know the problem...
    ...now to find a solution.

    Edited once, last by Sjeiti (February 16, 2011 at 12:25 AM).

  • Try a delayedcall(0 , yourtweenfunction());
    Maybe that prevents it to be overwritten (maybe stack overflow?), or put a wait(blend) on the end of the tween, so the code doesn't run any further untill the tween is done.

    I had the same problem, when creating complicated automated paths, where you go from 1 moveto to another with a tween. It tends to do only the last one, I solved this with above solution, see what works for you :) I alsoo had a problem with tween using greensocks library.

    It's alsoo my job to code :P But I avoid complicated xml actions, I rather let AS3 do the complicated stuff and communicate the final output to krpano :)

  • Tried both your suggestions and failed.
    I would rather do this in as3 but it's for iOs and since krpano js does not really have an api I'm forced to use the xml actions.

    Small testcase here:

    I have no idea why the first one works and the second one doesn't though...
    Think I'm just gonna give up on this one, it's taking me too long.

  • Hi Sjeiti,

    About your testcase above:
    I have not looked your code as it is ... I just looked to point something about variables (variable <---> array).
    Try this code


    the resulting traces are:

    Code
    INFO: var.foo = 0 -- var.bar = 1 -- var.baz = 2
    INFO: bar.foo = 31 -- bar.bar = 21 -- bar.baz = 11
    INFO: bar[foo].foo = 31 -- bar[foo].bar = 21 -- bar[foo].baz = 11
    INFO: bar[bar].foo = 31 -- bar[bar].bar = 21 -- bar[bar].baz = 11


    Now, change the definition order of the variable bar:


    the resulting traces are:

    Code
    INFO: var.foo = 0 -- var.bar = 1 -- var.baz = 2
    INFO: bar.foo = bar.foo -- bar.bar = bar.bar -- bar.baz = bar.baz
    INFO: bar[foo].foo = 30 -- bar[foo].bar = 20 -- bar[foo].baz = 10
    INFO: bar[bar].foo = 31 -- bar[bar].bar = 21 -- bar[bar].baz = 11


    Conclusion: it seems that a variable and an array can not be mixed with the same name....


    About multiple tweens:

    The problem in your example is how you think about the use of the donecall option inside the tween(variable,destinationvalue,time*,tweentype*,donecall*) Try this code instead of your:

    Code
    set(plugin[map].foo, -300);
    		set(plugin[maphide].foo, 400);
    		set(asdf,'map');
    		tween(plugin[get(asdf)].foo, 132, 0.5, linear, WAIT); <!-- WAITING the end of the tween before continuing with the rest of the actions list-->
    		trace('???????tweenTestDone ',plugin[get(asdf)].foo);
    		set(asdf,'maphide');
    		tween(plugin[get(asdf)].foo, 312, 0.5, linear,
    				trace('!!!!!!!tweenTestDone ',plugin[get(asdf)].foo);
    			);


    Note the WAIT in line 4.

    Hope this help.

    SAlut.

    Edited 5 times, last by michel (February 16, 2011 at 6:14 PM).

  • Hey Michel,

    (took a while before I got around to this problem again)
    Thanks for clarifying that about the variables. That makes sense.

    Unfortunately the solution you gave does not really solve the problem of the first source code i posted (the code after that was just to show how a tween fails when the same variable is used with different values).
    I'm calling a single action twice: once to turn the old layer off, once to turn the new layer on. When I try to use tweens instead of toggleing visibility the second time the action is called it overrides the tween from the first (it seems closures like in actionscript and javascript do not apply here).
    Besides, it is definitely my intention to call two tweens simultaneously. It wouldn't be much of a crossfade if I didn't.

  • Hi Sjeiti,

    Try adding a WAIT in your tween:

    Hope this Help...


    Hi VN2011 *smile* ,

    Congratulation, your 1000 post (and growing) *thumbup* !!!

    Many people here will thanks you a lot!!! About me, I have no time (I would like)!

    SAlut *wink* .

  • Hi Sjeiti,

    Quote

    Only it's still not a crossfade, due to the wait of course.

    I missed the need of crossfade *huh* ... Sorry *rolleyes* ...
    The problem I thing is the use of variables...

    Quote

    .....tween fails when the same variable is used with different values

    So, try avoiding to set variables from the parameters, instead, try use them directly...
    something like this:

    Hope this help.

    SAlut.

  • Hi Zephyr *smile* ,

    Quote

    btw, what is this level[%1].point.count ?

    It remember me the points of an Polygonal Hotspots... But, without an example, I do not know the particular use made by Sjeiti ...

    BTW, what about your Interface Template project? You must have becoming an PHP master for now *cool* !!


    Hi Sjeiti,

    I have made a working example using your code... It is based on a modified flyout-more-hotspots.xml from the Krpano examples...
    So, copy the examples\xml-usage\flyout-hotspots folder and replace the flyout-more-hotspots.xml by the one attached below...

    Hope this help...

    SAlut.

  • Quote

    btw, what is this level[%1].point.count

    'level' is a custom node I use to store the data for the floorplans interface. So the above will tell me the number of panorama's (or hotspots on the floorplan) for a certain floor.

    Got a test running here(js only, since I'm targeting iOs devices)
    XML here (bit messy since I generated parts of the XML)

    michel

    Thanks!!!... I'm gonna try it as soon as I find the time (all work and no play over here).

    gr

    Ron

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!