pyclutter的动作有以下几种:
actor.set_reactive(True)设置为可运动
clutter.BehaviourScale(x_scale_start, y_scale_start, x_scale_end, y_scale_end, alpha=True)缩放
clutter.Alpha(timeline=None, func=None, data=None) 运动效果 func为效果函数
clutter.BehaviourDepth(alpha=True, depth_start, depth_end) 沿 Z 轴移动;(z值)
clutter.BehaviourEllipse(alpha, x, y, width, height, start, end)沿椭圆形曲线移动;
clutter.BehaviourOpacity(alpha=alpha, opacity_start=0x33, opacity_end=200)不透明度,0为完全透明
clutter.BehaviourPath(alpha=alpha,path=clutter.Path)按照轨迹移动
clutter.BehaviourRotate(alpha=True, axis, direction=True, angle_start, angle_end) 旋转
本文主要是记录BehaviourPath的相关内容, clutter.BehaviourPath是按照轨迹移动的动作。
他有两个参数,一个是alpha,另一个是clutter.Path属性的路径对象path
path可以通过如下方法设定:
path=clutter.Path('M 100 100 L 200 200')
clutter.Path的参数为路径描述,由clutter.Path.__doc__可的,该描述方法符合SVG格式。
SVG中对path的描述方法:
下面的命令可用于路径数据:
M = moveto(直接跳跃过去)
L = lineto(直线路径)
H = horizontal lineto 水平移动
V = vertical lineto 竖直移动
C = curveto 折线
S = smooth curveto 曲线
Q = quadratic Belzier curve
T = smooth quadratic Belzier curveto
A = elliptical Arc 椭圆
Z = closepath(回到起点)
注释:以上所有命令均允许小写字母。大写表示绝对定位,小写表示相对定位。
例如 'M 10 10 L 100 100 Z'
一个动作通常由以下步骤生成;
actor.set_reactive(True)
timeline = clutter.Timeline(3000)
timeline.set_loop(True)
alpha = clutter.Alpha(timeline, clutter.EASE_OUT_EXPO)
p_behavior = clutter.BehaviourPath(alpha, clutter.Path('l %d %d Z'%(400,400)))
p_behavior.apply(actor)
timeline.start()
clutter.main()
1 设定actor可移动
2 设定时间轴,及该动作占用总帧数
3 是否循环(默认不循环)
4 设定alpha,alpha是管理动作速度方面的对象
5 设定BehaviourPath对象
6 选择actor
7 启动时间轴
8 进入clutter主循环
这里边path的描述参数 和 alpha的参数是两个重点
clutter.Alpha的第二个参数是clutter._clutter.AnimationMode类,用来控制动作快慢的函数。下图横坐标为时间轴,竖坐标为变化程度,各个参数的示意图如下。例如clutter.EASE_IN_QUINT,变化为先慢后快。