Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

make man jump in a game

Posted on 2004-04-03
3
Medium Priority
?
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses

610 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