×
Namespaces

Variants
Actions
(Difference between revisions)

Creating Simple Animations with Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Tomi_ (Talk | contribs)
(Tomi - - Easing curves)
Tomi_ (Talk | contribs)
m (Tomi -)
Line 37: Line 37:
 
File:EaseInOutQuad.png|In in-out-quad easing curve the speed of the animation accelerates in the beginning and slows down in the end. The image is taken from site http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html which shows graphs for several easing curves.
 
File:EaseInOutQuad.png|In in-out-quad easing curve the speed of the animation accelerates in the beginning and slows down in the end. The image is taken from site http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html which shows graphs for several easing curves.
 
</gallery>
 
</gallery>
 +
 +
=== Usage ===
 +
 +
<code java>
 +
public class MyCanvas
 +
    extends Canvas
 +
    implements AnimationListener
 +
{
 +
    // Constants
 +
...
 +
    private static final int ANIMATION_DURATION = 500;
 +
    private static final int EASING_CURVE = IntAnimation.EASING_CURVE_INOUTQUAD;
 +
 +
    // Members
 +
...
 +
    private IntAnimation _animation = null;
 +
...
 +
 +
    /**
 +
    * Constructor.
 +
    */
 +
    public MyCanvas() {
 +
        super();
 +
        ...       
 +
        _animation = new IntAnimation();
 +
        _animation.setListener(this);
 +
        ...
 +
</code>
 +
 +
<code java>
 +
    /**
 +
    * @see AnimationListener#onAnimatedValueChanged(int)
 +
    */
 +
    public void onAnimatedValueChanged(int value) {
 +
        // Handle the value
 +
        ...
 +
        repaint();
 +
    }
 +
 +
    /**
 +
    * @see AnimationListener#onAnimationStateChanged(int)
 +
    */
 +
    public void onAnimationStateChanged(int state) {
 +
        switch (state) {
 +
            case IntAnimation.STATE_RUNNING:
 +
                ...
 +
                break;
 +
            case IntAnimation.STATE_STOPPED:
 +
                ...
 +
                break;
 +
            case IntAnimation.STATE_FINISHED:
 +
                ...
 +
                break;
 +
            default:
 +
                break;
 +
        }
 +
    }
 +
</code>
 +
 +
Then just let it rip:
 +
<code java>
 +
        if (_animation.start(from, to, ANIMATION_DURATION, EASING_CURVE))
 +
        {
 +
            // Animation successfully started!
 +
        }
 +
        else {
 +
            // Failed to start the animation! Handle this situation gracefully.
 +
            _animation.stop();
 +
        }
 +
</code>
  
 
== Summary ==
 
== Summary ==

Revision as of 15:55, 27 June 2013

This article explains how to ...

Article Metadata
CompatibilityArticle
Created: (28 Jun 2013)
Last edited: Tomi_ (27 Jun 2013)

Contents

Introduction

Implementation

Architecture

Animation-fw-architecture.png

Easing curves

Usage

public class MyCanvas
extends Canvas
implements AnimationListener
{
// Constants
...
private static final int ANIMATION_DURATION = 500;
private static final int EASING_CURVE = IntAnimation.EASING_CURVE_INOUTQUAD;
 
// Members
...
private IntAnimation _animation = null;
...
 
/**
* Constructor.
*/

public MyCanvas() {
super();
...
_animation = new IntAnimation();
_animation.setListener(this);
...
    /**
* @see AnimationListener#onAnimatedValueChanged(int)
*/

public void onAnimatedValueChanged(int value) {
// Handle the value
...
repaint();
}
 
/**
* @see AnimationListener#onAnimationStateChanged(int)
*/

public void onAnimationStateChanged(int state) {
switch (state) {
case IntAnimation.STATE_RUNNING:
...
break;
case IntAnimation.STATE_STOPPED:
...
break;
case IntAnimation.STATE_FINISHED:
...
break;
default:
break;
}
}

Then just let it rip:

        if (_animation.start(from, to, ANIMATION_DURATION, EASING_CURVE))
{
// Animation successfully started!
}
else {
// Failed to start the animation! Handle this situation gracefully.
_animation.stop();
}

Summary

229 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×