自动旋转与循环浏览代码分享

使用说明

使用说明

需求说明:每个数字之后的一句话说明,即小标题

代码位置:在代码区域之前的文字

生效的关键代码部分:加粗标出

对关键代码的简单说明:在代码区域之后的文字

 

最简单的自动旋转代码

将方框内代码替换原有的<autorotate> 标签,如果原先没有<autorotate> 标签,则选择放在<scene>标签的外面的空白处。

<autorotate enabled=”true” />

enabledtrue代表激活自动旋转。

带各种设置的自动旋转代码

将方框内代码替换原有的<autorotate> 标签,如果原先没有<autorotate> 标签,则选择放在<scene>标签的外面的空白处。

<autorotate enabled=”true”

waittime=”5.0″

speed=”-3.0″

horizon=”0.0″

tofov=”120.0″

/>

waittime代表在最近一次用户交互行为之后要开始自动旋转之前的等待时间。以秒为单位。

speed为旋转速度。当该数值为正值时向右旋转,为负值时向左旋转。

horizon为场景要旋转至的水平位置。

tofov为旋转中要达到的视场。

场景开始时旋转,点击按钮切换旋转状态

1. 将下述方框的任一代码(A或B)替换原有的<autorotate> 标签,如果原先没有<autorotate> 标签,则选择放在<scene>标签的外面的空白处。

代码A

<autorotate enabled=”true” />

代码B

<autorotate enabled=”true”

waittime=”5.0″

speed=”-3.0″

horizon=”0.0″

tofov=”120.0″

/>

2. 在对应的按钮,通常为<layer>标签中找到onclick属性替换,如果没有onclick属性则直接添加。

<layer … onclick=”switch(autorotate.enabled);” />

没有按钮控制的循环浏览场景

自动旋转场景,场景旋转一圈后自动进入下一个场景,最后一个场景浏览结束后,进入第一个场景。

1. 将下述方框的任一代码(A或B)替换原有的<autorotate> 标签,如果原先没有<autorotate> 标签,则选择放在<scene>标签的外面的空白处。

代码A

<autorotate enabled=”true” />

代码B

<autorotate enabled=”true”

waittime=”5.0″

speed=”-3.0″

horizon=”0.0″

tofov=”120.0″

/>

2. 在<krpano>标签的onstart属性中检查是否有startup,通常默认情况下都有startup。找到下面的代码

<action name=”startup”>

if(startscene === null, copy(startscene,scene[0].name));

loadscene(get(startscene), null, MERGE);

</action>

改为

<action name=”startup”>

if(startscene === null, copy(startscene,scene[0].name));

loadscene(get(startscene), null, MERGE);

if(autorotate.enabled,bombtimer(0));

</action>

3. 然后在xml文件中加入下面代码:

<events onmousedown=”set(bt,0);” />

<action name=”bombtimer”>

set(autorotate.enabled,true);

set(bt,%1);

add(bt,1);

delayedcall(1, bombtimer(get(bt)));

copy(bt_1,autorotate.speed);

Math.abs(bt_1);

div(bt_2,360,bt_1);

add(bt_2,autorotate.waittime);

if(bt GE bt_2, set(bt,0); nextscene(););

</action>

<action name=”nextscene”>

set(ns, get(scene[get(xml.scene)].index));

set(maxs, get(scene.count));

add(ns,1);

if(ns == maxs, set(ns,0));

loadscene(get(scene[get(ns)].name), null, MERGE, BLEND(1.5));

</action>

按钮控制的自动旋转

1. 将下述方框的任一代码(A或B)替换原有的<autorotate> 标签,如果原先没有<autorotate> 标签,则选择放在<scene>标签的外面的空白处。

代码A

<autorotate enabled=”true” />

代码B

<autorotate enabled=”true”

waittime=”5.0″

speed=”-3.0″

horizon=”0.0″

tofov=”120.0″

/>

2. 在对应的按钮,通常为<layer>标签中找到onclick属性替换,如果没有onclick属性则直接添加。

<layer … onclick=”switch(autorotate.enabled);” … />

有按钮控制的循环浏览场景

自动旋转场景,场景旋转一圈后自动进入下一个场景,最后一个场景浏览结束后,进入第一个场景。

1. 将下述方框的任一代码(A或B)替换原有的<autorotate> 标签,如果原先没有<autorotate> 标签,则选择放在<scene>标签的外面的空白处。

代码A

<autorotate enabled=”true” />

代码B

<autorotate enabled=”true”

waittime=”5.0″

speed=”-3.0″

horizon=”0.0″

tofov=”120.0″

/>

2. 在<krpano>标签的onstart属性中检查是否有startup,通常默认情况下都有startup。找到下面的代码

<action name=”startup”>

if(startscene === null, copy(startscene,scene[0].name));

loadscene(get(startscene), null, MERGE);

</action>

改为

<action name=”startup”>

if(startscene === null, copy(startscene,scene[0].name));

loadscene(get(startscene), null, MERGE);

if(autorotate.enabled,bombtimer(0));

</action>

3. 然后在xml文件中加入下面代码:

<events onmousedown=”set(bt,0);” />

<action name=”bombtimer”>

set(autorotate.enabled,true);

set(bt,%1);

add(bt,1);

delayedcall(bomb,1, bombtimer(get(bt)));

copy(bt_1,autorotate.speed);

Math.abs(bt_1);

div(bt_2,360,bt_1);

add(bt_2,autorotate.waittime);

if(bt GE bt_2, set(bt,0); nextscene(););

</action>

<action name=”nextscene”>

set(ns, get(scene[get(xml.scene)].index));

set(maxs, get(scene.count));

add(ns,1);

if(ns == maxs, set(ns,0));

loadscene(get(scene[get(ns)].name), null, MERGE, BLEND(1.5));

</action>

4. 在对应的按钮,通常为<layer>标签中找到onclick属性替换,如果没有onclick属性则直接添加。

onclick=”if(autorotate.enabled,set(autorotate.enabled,false);stopdelayedcall(bomb),set(autorotate.enabled,true);bombtimer(0));”

 

发表评论