Hi all I recently have this problem and got stucked:

At the momment I try to animate the Person.png image pressing the down key pad using setFrameSequence() nothing happens it just freeze the image.

But if I try to use any other arrow key pad it works just fine because I'm using nextFrame()

I need some advice to get the setFrameSequence() animating the image propperly : )

and here is the code:


__________________________________________________ __________________________
// MAIN Midlet CLASS

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class WandererMIDlet extends MIDlet implements CommandListener {
private WCanvas canvas;

public void startApp() {
if (canvas == null) {
canvas = new WCanvas(Display.getDisplay(this));
Command exitCommand = new Command("Exit", Command.EXIT, 0);
canvas.addCommand(exitCommand);
canvas.setCommandListener(this);
}

// Start up the canvas
canvas.start();
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {
canvas.stop();
}

public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) {
destroyApp(true);
notifyDestroyed();
}
}
}

__________________________________________________ __________________________

// WCanvas CLASS


import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.util.*;
import java.io.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class WCanvas extends GameCanvas implements Runnable {
private Display display;
private boolean sleeping;
private long frameDelay;
private Sprite personSprite;
private Player musicPlayer;

public WCanvas(Display d) {
super(true);
display = d;

// Set the frame rate (30 fps)
frameDelay = 20;
}

public void start() {
// Set the canvas as the current screen
display.setCurrent(this);

try {
personSprite = new Sprite(Image.createImage("/Person.png"), 90, 90);
personSprite.setPosition((getWidth() - personSprite.getWidth()) / 2,
(getHeight() - personSprite.getHeight()) / 2);
}
catch (IOException e) {
System.err.println("Failed loading images!");
}

// Initialize and start the music player
try {
InputStream is = getClass().getResourceAsStream("Music.mid");
musicPlayer = Manager.createPlayer(is, "audio/midi");
musicPlayer.prefetch();
musicPlayer.setLoopCount(-1);
musicPlayer.start();
}
catch (IOException ioe) {
}
catch (MediaException me) {
}

// Start the animation thread
sleeping = false;
Thread t = new Thread(this);
t.start();
}

public void stop() {
// Close the music player
musicPlayer.close();

// Stop the animation
sleeping = true;
}

public void run() {
Graphics g = getGraphics();

// The main game loop
while (!sleeping) {
update();
draw(g);
try {
Thread.sleep(frameDelay);
}
catch (InterruptedException ie) {}
}
}

private void update() {
int keyState = getKeyStates();

if ((keyState & LEFT_PRESSED) != 0) {
personSprite.prevFrame();
}
else if ((keyState & RIGHT_PRESSED) != 0){
personSprite.nextFrame();
}
if ((keyState & UP_PRESSED) != 0) {
personSprite.nextFrame();
}
else if ((keyState & DOWN_PRESSED) != 0) {
int[] a = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20 };
personSprite.setFrameSequence(a);
personSprite.nextFrame();

}

}

private void draw(Graphics g) {
g.setColor( 255, 255, 255 );
g.fillRect(0, 0, getWidth(), getHeight());
personSprite.paint(g);
flushGraphics();
}
}


__________________________________________________ __________________________