Solved

Move

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now