×
Namespaces

Variants
Actions
Revision as of 09:05, 10 May 2013 by hamishwillee (Talk | contribs)

Series 40 Touch API - Frame Animator API (Chinese)

From Nokia Developer Wiki
Jump to: navigation, search
WP Metro Icon Chinese.png
Article Metadata

代码示例
兼容于
平台:
Series 40

文章
max.chen 在 Max.chen 创建
最后由 hamishwillee 在 10 May 2013 编辑

Frame Animator API 用来计算动力学和线性内插动画。例如,可以用于处理滑动或拖拽动作。相关文档可以参考 S40 Touch API (1) - Gesture API


S40 touch api animator 1.png

Contents

第一步

参考文档 S40 Touch API (1) - Gesture API中的说明,先定义一个GestureListener ,然后实现FrameAnimatorListener接口。

class FrameAnimatorCanvas extends Canvas implements FrameAnimatorListener
{
public void animate(FrameAnimator frameAnimator,
short x, short y,
short delta, short deltaX, short deltaY,
boolean lastFrame) {
. . .
}
}

第二步

创建一个FrameAnimator实例,并注册FrameAnimatorListener接口。

frameAnimator = new FrameAnimator();
 
frameAnimator.register(centerX, centerY, maxFps, maxPps, this);

第三步

在GestureListener 接口中的gestureAction()方法里,触发FrameAnimator的drag()和kineticScroll()方法,开始动画的计算和绘制。

public void gestureAction(Object container, 	GestureInteractiveZone gestureZone, GestureEvent event) {
 
switch( event.getType() );
case GestureInteractiveZone.GESTURE_DRAG:
frameAnimator.drag( event.getStartX()+event.getDragDistanceX(), event.getStartY() +event.getDragDistanceY() );
... ...
 
case GestureInteractiveZone.GESTURE_FLICK:
frameAnimator.kineticScroll( event.getFlickSpeed(), FrameAnimator.FRAME_ANIMATOR_FREE_ANGLE,
FrameAnimator.FRAME_ANIMATOR_FRICTION_MEDIUM, event.getFlickDirection()
);
 
... ...


代码示例

Media:FrameAnimator.zip 运行这个例子后,试着做一下flick,是不是很有意思!

相关链接

213 page views in the last 30 days.
×