立体图层动效可以实现多个图层叠加的效果。根据设置的不同z值,展示图层的不同空间位置。与传感器标签<VariableBinders>结合使用,左右上下晃动手机时呈现相机角度变换的效果;或者通过左右上下滑动屏幕来改变相机的角度。交互方式可以通过自定义的方式来设计长按或者点击,来实现左右浏览或者调节图层远近。
<MultiLayer gravityX="" gravityY="" pitchAngle="" sidesAngle="" touchType="" stepX="" stepZ="" blur="" visibility=""> <!--远处的图层--> <Layer x="" y="" z="" w="" h="" src="" staticCondition=""/> <!--中间的图层--> <Layer x="" y="" z="" w="" h="" src=""/> <!--近处的图层--> <Layer x="" y="" z="" w="" h="" src="" delay="" repeat=""> <Source frame="" time=""/> <Source frame="" time=""/> <Source frame="" time=""/> </Layer> </MultiLayer>
| 参 数 | 类 型 | 选 项 | 注 释 |
|---|---|---|---|
| gravityX | 数值 | 选填 | x方向的重力数值。使用表达式,与传感器标签<VariableBinders>结合使用。应用于模式0和2 |
| gravityY | 数值 | 选填 | y方向的重力数值。使用表达式,与传感器标签<VariableBinders>标签结合使用。应用于模式0和2 |
| touchType | 数值 | 选填 | 图层交互模式,数值为0-3,支持表达式,默认值为0。目前共有4种模式:0,重力感应模式;1,上下左右滑动改变相机角度模式;2,重力感应和滑动改变角度模式;3,调节相机远近和左右浏览模式。 |
| pitchAngle | 字符串 | 选填 | 俯视和仰视角度的最大值,通过上下滑动切换角度。取值为“top,-up”,top为正数,up为正数,中间以英文逗号隔开。例如:"8,-8"。应用于模式1和2 |
| sidesAngle | 字符串 | 选填 | 左侧和右侧角度的最大值,通过左右滑动切换角度。取值为“left,-right”,left为正数,right为正数,中间以英文逗号隔开。例如:"8,-8"。应用于模式1和2 |
| stepX | 数值 | 选填 | 图层左右浏览的步长,使用表达式计算累加/减,例如:#stepX+0.1。应用于模式3。 |
| stepZ | 数值 | 选填 | 图层靠近远离的步长,使用表达式计算累加/减,例如:#stepZ+0.1。应用于模式3。 |
| blur | 数值 | 选填 | 点击图层靠近时,渐变模糊程度,范围是[0,10],默认为0清晰。 |
| visibility | 数值 | 选填 | 控制可见性,0 不可见 1可见,默认为1。 |
由于图片距离越远(即z值越小),图片则越小且x和y值也有偏差。若需要在远处也达到图片原始大小和位置一样的效果,需要对x和y以及宽高进行换算。关系换算如下:
例如图片原始属性:x=X,y=Y,w=W,h=H。
则空间各位置的图片属性如下:
设z=Z,z值范围[-10,7],
x=X*((10-Z)/3)-#screen_width/(6/(7-Z));
y=Y*((10-Z)/3)-#screen_height/(6/(7-Z));
w=W*((10-Z)/3);
h=H*((10-Z)/3)。
当z值为7时,不需要进行换算,可以直接显示图片大小和位置。
| 参 数 | 类 型 | 选 项 | 注 释 |
|---|---|---|---|
| x | 数值 | 选填 | 相对于屏幕左上角的x坐标,支持表达式,默认值为0。因透视投影的影响,当在远处时显示的位置也不同,跟z值有关。 |
| y | 数值 | 选填 | 相对于屏幕左上角的y坐标,支持表达式,默认值为0。因透视投影的影响,当在远处时显示的位置也不同,跟z值有关。 |
| z | 数值 | 选填 | 图层的空间位置,相机视野内的取值范围为[-10,7]之间的浮点数,支持表达式,默认值为0。屏幕向外为正方向。因使用透视投影,物体显示效果为远小近大。设计图层Layer标签时,需要根据z值从小到大赋值,即图层从远到近的顺序绘制。 |
| w | 数值 | 必填 | 图片的宽,支持表达式,w和width写法都可以。 |
| h | 数值 | 必填 | 图片的高,支持表达式,h和height写法都可以。 |
| src | 字符串 | 必填 | 图片的资源,例如:bj.png |
| staticCondition | 字符串 | 选填 | 图层是否静态,不随相机位置改变,取值为true和false。为true时表示图层静态,不发送改变。默认为false。 |
| delay | 数值 | 选填 | 帧动画延迟播放属性,默认不延迟。 |
| repeat | 数值 | 选填 | 帧动画重复次数,默认为无限重复。 |
| 参 数 | 类 型 | 选 项 | 注 释 |
|---|---|---|---|
| frame | 字符串 | 必填 | 帧动画图片资源,例如:zhen_1.png |
| time | 数值 | 必填 | [0-~],相对于起始帧的间隔时间(毫秒),也是动画持续时间,帧图片人肉眼能识别时间延时为300ms左右,不小于0。 |
<MultiLayer gravityX="0" gravityY="0" pitchAngle="5,-5" sidesAngle="8,-8" touchType="3" stepX="0" stepZ="0"> <Layer x="-1080*2.7" y="-2400*2.7" z="-8+not(#kg%2)*max(#sj6,0)+(#kg%2)*(#zzz/50)*8" w="1080*6.4" h="2400*6.4" src="bg_5.jpg"/> <Layer x="-1080*2.7" y="-2400*2.7" z="-8+not(#kg%2)*max(#sj5,0)+(#kg%2)*(#zzz/50)*20" w="1080*6.4" h="2400*6.4" src="bg_4.png"/> <Layer x="-1080*2.7" y="-2400*2.7" z="-8+not(#kg%2)*max(#sj4,0)+(#kg%2)*(#zzz/50)*25" w="1080*6.4" h="2400*6.4" src="bg_3.png"/> <Layer x="-1080*2.7" y="-2400*2.7" z="-8+not(#kg%2)*max(#sj3,0)+(#kg%2)*(#zzz/50)*30" w="1080*6.4" h="2400*6.4" src="bg_2.png"/> <Layer x="-1080*2.7" y="-2400*2.7" z="-8+not(#kg%2)*max(#sj2,0)+(#kg%2)*(#zzz/50)*40" w="1080*6.4" h="2400*6.4" src="bg_1.png"/> <Layer x="-1080*2.7" y="-2400*2.7" z="-8+not(#kg%2)*max(#sj1,0)+(#kg%2)*(#zzz/50)*50" w="1080*6.4" h="2400*6.4" src="bg_0.png"/> </MultiLayer>
示例一:该示例中通过按钮切换控制不同的交互模式,重力感应模式跟VariableBinders标签结合使用;设置角度变换模式的俯视仰视和左右侧角度的最大值;通过长按按钮控制图层靠近,抬起时图层远离,左右滑动控制图层左右浏览效果;近处的图层实现帧动画效果。
<VariableBinders> <SensorBinder type="gravity"> <Variable name="x_gra" index="0"/> <Variable name="y_gra" index="1"/> </SensorBinder> </VariableBinders> <MultiLayer gravityX="-#x_gra" gravityY="#y_gra" pitchAngle="5,-5" sidesAngle="8,-8" touchType="#touchtype" stepX="#stepX" stepZ="#step" blur="1.0" visibility="1"> <Layer x="0" y="0" z="0" w="#screen_width" h="#screen_height" src="gufeng_2.png"/> <Layer x="0" y="0" z="2" w="#screen_width" h="#screen_height" src="bg.jpg"/> <Layer x="0" y="0" z="4" w="#screen_width" h="#screen_height" src="gufeng_4.png"/> <Layer x="200" y="600" z="4.5" w="600" h="750" src="zuida1_1.png" delay="1000" repeat="4"> <Source frame="zuida1_1.png" time="0"/> <Source frame="zuida1_1.png" time="400"/> <Source frame="zuida1_2.png" time="800"/> <Source frame="zuida1_3.png" time="1200"/> <Source frame="zuida1_4.png" time="1600"/> <Source frame="zuida1_5.png" time="2000"/> <Source frame="zuida1_1.png" time="2500"/> <Source frame="zuida1_1.png" time="3000"/> <Source frame="zuida1_2.png" time="3500"/> <Source frame="zuida1_3.png" time="4000"/> <Source frame="zuida1_4.png" time="4500"/> <Source frame="zuida1_5.png" time="5000"/> </Layer> </MultiLayer> <!-- 按钮切换控制4种模式 --> <Image src="1.png" w="200" h="200" x="0" y="0"/> <Button x="0" y="0" w="200" h="200"> <Trigger action="up"> <VariableCommand condition="lt(#touchtype,4)" name="touchtype" expression="#touchtype+1"/> <VariableCommand condition="ge(#touchtype,4)" name="touchtype" expression="0" /> </Trigger> </Button> <!-- 长按按钮时图层靠近,抬起时图层恢复 --> <Var name="isTouched" expression="0"/> <Var name="sj"> <VariableAnimation> <AniFrame value="0" time="0"/> <AniFrame value="9999999999999999" time="9999999999999999"/> </VariableAnimation> </Var> <Var name="maoy" expression="#sj" threshold="1"> <Trigger> <VariableCommand name="step" expression="#step+0.1" condition="eq(#isTouched,1)*le(#step,6.9)"/> <VariableCommand name="step" expression="#step-0.1" condition="eq(#isTouched,2)*ge(#step,0.1)"/> </Trigger> </Var> <Image src="5.png" w="200" h="200" x="0" y="1500"/> <Button x="0" y="1500" w="200" h="200"> <Trigger action="down"> <VariableCommand name="isTouched" expression="1"/> </Trigger> <Trigger action="up"> <VariableCommand name="isTouched" expression="2"/> </Trigger> </Button> <!-- 左右滑动浏览 --> <Slider> <StartPoint x="0" y="0" w="#screen_width" h="#screen_height"> </StartPoint> <EndPoint x="-350" y="0" w="50" h="#screen_height"> <Trigger action="up"> <VariableCommand name="stepX" expression="#stepX-0.1"/> </Trigger> <Path x="0" y="0"> <Position x="0" y="0"/> <Position x="-350" y="0"/> </Path> </EndPoint> </Slider> <Slider> <StartPoint x="0" y="0" w="#screen_width" h="#screen_height"> </StartPoint> <EndPoint x="350" y="0" w="50" h="#screen_height"> <Trigger action="up"> <VariableCommand name="stepX" expression="#stepX+0.1"/> </Trigger> <Path x="0" y="0"> <Position x="0" y="0"/> <Position x="350" y="0"/> </Path> </EndPoint> </Slider>