You are not logged in.

1

Tuesday, February 15th 2011, 5:51pm

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:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!-- show or hide level
	%1:Object	level
	%2:Boolean	show or hide
	%3:Boolean	no alpha animation
-->
<action name="showLevel">
	<!-- level visibility -->
	set(sLayer,get(level[%1].val));
	set(bShow,get(%2));
	trace('showLevel ',%1,' ',%2,' ',%3,'   p: ',level[%1].point.count);
	if(%3==true,<!-- damn you stupid crossfade -->
		set(plugin[get(sLayer)].alpha,1);
		set(plugin[get(sLayer)].visible,get(bShow));
	,
		set(fAlpha,0);
		if(bShow==true,
			set(fAlpha,1);
			set(plugin[get(sLayer)].alpha,0);
			set(plugin[get(sLayer)].visible,true);
		);
	
		tween(plugin[get(sLayer)].alpha, get(fAlpha), 0.25, linear,
			if (bShow==false,
				set(plugin[get(sLayer)].visible, false);
			);
			set(plugin[get(sLayer)].alpha,1);
			trace('tweendone ',sLayer,' ',bShow); <!-- this is only traced once, even if the action is called twice -->
		);
	);
</action>


Hope anyone can figure this out, caus I'm stumped :-)

Zephyr

Professional

Posts: 1,003

Location: Netherlands

Occupation: Web developer

  • Send private message

2

Tuesday, February 15th 2011, 6:53pm

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?

3

Tuesday, February 15th 2011, 11:53pm

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.

Source code

1
2
3
4
5
6
7
8
9
10
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.

This post has been edited 1 times, last edit by "Sjeiti" (Feb 16th 2011, 12:25am)


Zephyr

Professional

Posts: 1,003

Location: Netherlands

Occupation: Web developer

  • Send private message

4

Wednesday, February 16th 2011, 8:35am

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 :)

5

Wednesday, February 16th 2011, 1:17pm

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:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<var
	foo="0"
	bar="1"
	baz="2"
/>
<bar
	foo="3"
	bar="2"
	baz="1"
/>
<bar name="foo"
	foo="3"
	bar="2"
	baz="1"
/>
<bar name="bar"
	foo="3"
	bar="2"
	baz="1"
/>

<action name="startup">
	<!-- this works -->
	set(baz,var.foo);
	tween(get(baz), 132, 0.5, linear,
		trace('get(baz) done ',get(baz));
	);
	set(baz,bar.foo);
	tween(get(baz), 543, 0.5, linear,
		trace('get(baz) done ',get(baz));
	);
	<!-- this does not -->
	set(a,'foo');
	tween(bar[get(a)].foo, 132, 0.5, linear,
		trace('bar[get(a)].foo done ',get(bar[get(a)].foo));
	);
	set(a,'bar');
	tween(bar[get(a)].foo, 132, 0.5, linear,
		trace('bar[get(a)].foo done ',get(bar[get(a)].foo));
	);
</action>


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.

michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

6

Wednesday, February 16th 2011, 5:59pm

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

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<var
	foo="0"
	bar="1"
	baz="2"
/>
<bar 
	foo="3"
	bar="2"
	baz="1"
/>
<bar name="foo"
	foo="30"
	bar="20"
	baz="10"
/>
<bar name="bar"
	foo="31"
	bar="21"
	baz="11"
/>

<action name="truc">
trace('var.foo = ',var.foo,' -- var.bar = ',var.bar,' -- var.baz = ',var.baz);
trace('bar.foo = ',bar.foo,' -- bar.bar = ',bar.bar,' -- bar.baz = ',bar.baz);
trace('bar[foo].foo = ',bar[foo].foo,' -- bar[foo].bar = ',bar[foo].bar,' -- bar[foo].baz = ',bar[foo].baz);
trace('bar[bar].foo = ',bar[bar].foo,' -- bar[bar].bar = ',bar[bar].bar,' -- bar[bar].baz = ',bar[bar].baz);
);
</action>

the resulting traces are:

Source code

1
2
3
4
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:

Source code

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<bar name="foo"
	foo="30"
	bar="20"
	baz="10"
/>
<bar name="bar"
	foo="31"
	bar="21"
	baz="11"
/>
<bar 
	foo="3"
	bar="2"
	baz="1"
/>

the resulting traces are:

Source code

1
2
3
4
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:

Source code

1
2
3
4
5
6
7
8
9
		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.

This post has been edited 5 times, last edit by "michel" (Feb 16th 2011, 6:14pm)


VN2011

Professional

Posts: 1,336

Location: Duluth MN

  • Send private message

7

Thursday, February 17th 2011, 7:46pm


Hope this help.

SAlut.


Michel your back! You been gone a long time it is nice to see you posting again i for one have missed your valueable insight!

8

Monday, February 21st 2011, 9:24pm

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.

michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

9

Monday, February 21st 2011, 9:48pm

Hi Sjeiti,

Try adding a WAIT in your tween:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!-- show or hide level
	%1:Object	level
	%2:Boolean	show or hide
	%3:Boolean	no alpha animation
-->

<action name="showLevel">
	<!-- level visibility -->
	set(sLayer,get(level[%1].val));
	set(bShow,get(%2));
	trace('showLevel ',%1,' ',%2,' ',%3,'   p: ',level[%1].point.count);
	if(%3==true,<!-- damn you stupid crossfade -->
		set(plugin[get(sLayer)].alpha,1);
		set(plugin[get(sLayer)].visible,get(bShow));
	,
		set(fAlpha,0);
		if(bShow==true,
			set(fAlpha,1);
			set(plugin[get(sLayer)].alpha,0);
			set(plugin[get(sLayer)].visible,true);
		);
	
		tween(plugin[get(sLayer)].alpha, get(fAlpha), 0.25, linear, WAIT);
		if (bShow==false,
			set(plugin[get(sLayer)].visible, false);
		);
		set(plugin[get(sLayer)].alpha,1);
		trace('tweendone ',sLayer,' ',bShow); <!-- this is only traced once, even if the action is called twice -->
	);
</action>


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 ;-) .

10

Monday, February 21st 2011, 10:47pm

Hi....

I did try that... maybe I tried it wrong
will try again...


...


Ah yeah, my bad... it works without errors now.

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

michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

11

Monday, February 21st 2011, 11:57pm

Hi Sjeiti,

Quoted

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

Quoted

.....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:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!-- show or hide level
	%1:Object	level
	%2:Boolean	show or hide
	%3:Boolean	no alpha animation
-->

<action name="showLevel">
	<!-- level visibility -->
	trace('showLevel ',%1,' ',%2,' ',%3,'   p: ',level[%1].point.count);
	if(%3==true,<!-- damn you stupid crossfade -->
		set(hotspot[%1].alpha,1);
		set(hotspot[%1].visible,%2);
	,
		set(fAlpha,0);
		if(%2==true,
			set(fAlpha,1);
			set(hotspot[%1].alpha,0);
			set(hotspot[%1].visible,true);
		);
	
		tween(hotspot[%1].alpha, get(fAlpha), 0.25, linear, 
			if (%2==false,
				set(hotspot[%1].visible, false);
			);
			set(hotspot[%1].alpha,1);
			trace('tweendone ',sLayer,' ',%2); <!-- this is only traced once, even if the action is called twice -->
		);
	);
</action>


Hope this help.

SAlut.

Zephyr

Professional

Posts: 1,003

Location: Netherlands

Occupation: Web developer

  • Send private message

12

Tuesday, February 22nd 2011, 8:51am

awesome michel :)

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

michel

Professional

Posts: 1,153

Location: ANDORRA

Occupation: TV

  • Send private message

13

Tuesday, February 22nd 2011, 10:12am

Hi Zephyr *smile* ,

Quoted

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.
michel has attached the following file:

14

Tuesday, February 22nd 2011, 10:57am

Quoted

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