Solved

Move

Posted on 1998-07-31
3
190 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 50 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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 Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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.

696 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