moving sprite and firing sprite..help!!

I am doing an action game currently,that i need to make the sprite looks “always moving” while user is pressing any direction keys.

hence, i set a sequence for my sprite:

private static final int[] frmSeq = { 1, 2 ,0};

if ((keyState & LEFT_PRESSED) != 0) {
Essprite.move(-6, 0);
Essprite.nextFrame();
}

if ((keyState & RIGHT_PRESSED) != 0) {
Essprite.move(6, 0);
Essprite.nextFrame();
}

if ((keyState & UP_PRESSED) != 0) {
Essprite.move(0, -6);
Essprite.nextFrame();
}

if ((keyState & DOWN_PRESSED) != 0) {
Essprite.move(0, 6);
Essprite.nextFrame();
}

and, i want to make my firing sprite abit different. when i press fire the sprite will shows it is shooting something.

if ((keyState & FIRE_PRESSED) != 0) {
Essprite.setFrameSequence(null);
Essprite.setFrame(4);
Essprite.setFrameSequence(seq);
}

however, the program just hang after i press firing button.

anyone can help…?

I’ve answered here.

shmoove

shmoove ,thanks once again… :wink: :wink: :wink: :wink:


hi all,anyone can help me to solve this problem…?
after the initialization of the walking frame sequence it doesn’t work in order…
plz…

public class Escanvas extends GameCanvas implements Runnable {

private boolean isPlay;
private long delay;
private Sprite Essprite;
private Display display;
private static final int[] walkingseq = {0,1,2};
private static final int[] fireseq = {3,4};

public Escanvas(Display d){
super(true);
display = d;
delay = 180;
isPlay=true;

    }

public void start() {
    display.setCurrent(this);
    try {
    Essprite= new Sprite(Image.createImage("/res/test1.png"),17,17);
    Essprite.setFrameSequence(walkingseq);
    }catch (Exception e) {System.out.println("Error Loading Image");}

    Thread running = new Thread(this);
    running.start();
}

public void stop(){
    isPlay=false;
}
        

public void run() {

    Graphics g = getGraphics();


    while (isPlay==true) {
      
        input();
        drawScreen(g);
        
        
    try {
        Thread.sleep(delay);
    }
    catch (InterruptedException ie) {}
    
}
}


public void input(){
    
    
    
    int keyState = getKeyStates();
    
    Essprite.setFrameSequence(walkingseq);
                  
      if ((keyState & LEFT_PRESSED) != 0) {
      
        Essprite.move(-6, 0);
        Essprite.nextFrame();
        }
    
        if ((keyState & RIGHT_PRESSED) != 0) {
      
        Essprite.move(6, 0);
        Essprite.nextFrame();
        }
    
        if ((keyState & UP_PRESSED) != 0) {
      
        Essprite.move(0, -6);
        Essprite.nextFrame();
        }
    
        if ((keyState & DOWN_PRESSED) != 0) {
    
        Essprite.move(0, 6);
        Essprite.nextFrame();
        }
    
        if ((keyState & FIRE_PRESSED) != 0) {
      
          Essprite.setFrameSequence(fireseq);
          Essprite.nextFrame();

      
        }
      
      
}
    
  private void drawScreen(Graphics g) {
  
  g.setColor(0xffffff);
  g.fillRect(0,0,getWidth(),getHeight() );
  Essprite.paint(g);
  flushGraphics();

}

}

after the fire button is pressed, i’ve tried to initialize the Essprite.setFrameSequence(walkingseq) so that it will follow the sequence of {0,1,2};. However, it only run in {0,2} after the initilization.

i’ve tried to initialize the setFrame to the walking sequence after the fire action but it doesn’t seems working well. Sequence is out of order…

any solutionon this problem? i’ve so many ways but still the sequence is out of order after the initialization of setFrame’s frame sequence