Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  moving sprite and firing sprite..help!!  (Read 2131 times)
0 Members and 1 Guest are viewing this topic.
Offline wmchan78

Junior Newbie





« Posted 2005-10-29 15:14:48 »

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..?
Offline shmoove

Junior Member




Doh!


« Reply #1 - Posted 2005-10-30 10:18:43 »

I've answered here.

shmoove
Offline wmchan78

Junior Newbie





« Reply #2 - Posted 2005-10-30 16:37:02 »

shmoove ,thanks once again.... Wink Wink Wink Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wmchan78

Junior Newbie





« Reply #3 - Posted 2005-11-01 03:51:03 »

--------------------------------------------------------------------------------
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
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (8 views)
2014-09-21 00:34:41

moogie (7 views)
2014-09-21 00:26:15

UprightPath (22 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29

BurntPizza (52 views)
2014-09-07 01:13:42
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!