?
Solved

Move

Posted on 1998-07-31
3
Medium Priority
?
191 Views
Last Modified: 2010-03-30
i want to move image from down to top !
I am facing problem in calculating.
how should i do it ?
0
Comment
Question by:yeda
[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 2

Expert Comment

by:shchuka
ID: 1229401
Can you give a bit more details on what calculations you're trying to perform?
0
 

Author Comment

by:yeda
ID: 1229402
I have one gif of man .This gif is displayed initially on top of a building.I want this gif to run on building.So it looks like man running on top of a building.And i want to put a control on this object,such that whenever a player presses space bar this running man jumps down in a parabolic path.

Please supply the code !
Thanking U



0
 
LVL 2

Accepted Solution

by:
shchuka earned 100 total points
ID: 1229403
Well then.  Assume, your "man" is running from left to right with a constant speed (much easier calculations).

Assume, x is the horizonal coordinate of your image and y is the vertical (top-left corner of the image).  Further, let cvMan be the component with your image (say, canvas).

Then the code will be somethig like this:

int x = 0;
int y =0;
int xIncrement = 2;
while( not space-bar pressed ) {
    cvMan.setLocation(x,y);
    x += xIncrement;
}
//Now for the jump part
int t = 0;                                            //This is the time parameter
int yStart = y;
double gravity = 9.8;                           //Assume gravity on earth
while(y < whatever bottom level) {
    cvMan.setLocation(x,y);
    x += xIncrement;
    y = yStart + gravity * t * t / 2;
    t += 1;                                          //Change the icrement to increase/decrease the
                                                        //speed of fall
}

This is it.  Checking for a key press you can do using a class-level variable, say keypressed, which is initially is set to false, and in the key-press event set it to true.  Then the first loop will look like
while( !keypressed ) {   //and so on
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month11 days, 16 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