Solved

make man jump in a game

Posted on 2004-04-03
3
166 Views
Last Modified: 2012-05-04
public void jump(){
    int speed=-30;
    for(int i=0;i<60;i++){
    p.setY(speed);
    speed+=1;
    repaint();
    Thread.sleep(20);
    }
}

when i put this method no the constructor the man animates fine
but when i put a keyListener and press the up button the man goes to the desired location but i cant see him while hes going

0
Comment
Question by:omashhour
  • 2
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10747484
You need to increment the x,y coordinates on the timer until it arrives at the new location - not so much 'jump' as 'move'
0
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 50 total points
ID: 10747535
You should do your jump in a separate thread:

 public void jump() {
    Thread jumpThread = new Thread() {
      public void run() {
        try {
          int speed=-30;
          for(int i=0;i<60;i++){
            p.setY(speed);
            speed+=1;
            repaint();
            sleep(20);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    };
    jumpThread.start();
}
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10890985
:°)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now