Solved

make man jump in a game

Posted on 2004-04-03
3
169 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

828 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