?
Solved

Move

Posted on 1998-07-31
3
Medium Priority
?
193 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
  • 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 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