Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Move

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
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…
Suggested Courses

618 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