?
Solved

make man jump in a game

Posted on 2004-04-03
3
Medium Priority
?
172 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

752 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