Ejemplo de código: animación de la caída de una pelota en una dimensión

import net.rim.device.api.animation.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.animation.*;
public class SimpleAnimation extends UiApplication
{  
    public static void main( String[] args )
    {
        SimpleAnimation app = new SimpleAnimation();
        app.enterEventDispatcher();
    }
    public SimpleAnimation()
    {
        pushScreen(new AnimationScreen());
    }
}
class AnimationScreen extends MainScreen implements AnimatorListener
{
    private RectangleToMove _rect;
    private Animator  _animator;
    private Animation _xanimation;
    private Animation _yanimation;
    private boolean _bAnimating;
    public static final int BALL_WIDTH = 50;
    public AnimationScreen()
    {
        _bAnimating = false;
        int midScreen = Display.getWidth()/2;
        int endScreen = Display.getHeight();
        _rect = new RectangleToMove(midScreen,BALL_WIDTH);
        _animator = new Animator(30);
        _animator.setAnimatorListener(this);
        _yanimation = _animator.addAnimationFromTo(_rect.getY(),
          AnimatedScalar.ANIMATION_PROPERTY_SCALAR, BALL_WIDTH, 
          endScreen-BALL_WIDTH, Animation.EASINGCURVE_BOUNCE_OUT, 6000L);
        _yanimation.setRepeatCount(5f);
        _yanimation.begin(0);
    }
    protected void paint(Graphics g)
    {
        if(_bAnimating)
        {
           _rect.draw(g);
        }
    }
    public void animatorUpdate()
    {
        invalidate();
        doPaint();
    }
    public void animatorProcessing(boolean processing)
    {
        _bAnimating = processing;
    } 
}
class RectangleToMove
{
    private int xPos;
    private AnimatedScalar yPos;
    public void draw(Graphics g)
    {
        g.setBackgroundColor(Color.BLACK);
        g.clear();
        g.setColor(Color.SLATEGRAY);
        g.fillEllipse(xPos,yPos.getInt(),
          xPos+AnimationScreen.BALL_WIDTH,yPos.getInt(),xPos,
          yPos.getInt()+AnimationScreen.BALL_WIDTH,0,360);
    }    
    public int getX()
    {
        return xPos;
    }
    public AnimatedScalar getY()
    {
        return yPos;
    }
    RectangleToMove(int x,int y)
    {
        xPos = x;
        yPos = new AnimatedScalar(y);
    }
}
Tema siguiente: Recursos relacionados

¿Le ha resultado útil esta información? Envíenos sus comentarios.