Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am Currently working on One 2D Android Game,

In this game One ViewObject(Bitmap) is moving Across Screen On Parabola Path Like in this Image, But this Path is Static, the Static path is getting throught the Drawing with Fingure on canvas,

As Same as signature Drawing. enter image description here

The Bitmap Move code On this Static Path is

//animation step
private static int iMaxAnimationStep = 900;
private int iCurStep = 0;
private Path ptCurve = new Path(); //curve
private PathMeasure pm;            //curve measure
private float fSegmentLen;         //curve segment length


 //init smooth curve
    PointF point = aPoints.get(0);
    ptCurve.moveTo(point.x, point.y);

    for(int i = 0; i < aPoints.size() - 1; i++){
        point = aPoints.get(i);
        PointF next = aPoints.get(i+1);
  ptCurve.quadTo(point.x, point.y, (next.x + point.x) / 2, (point.y + next.y) / 2);
    }

    pm = new PathMeasure(ptCurve, false);
    fSegmentLen = pm.getLength() / iMaxAnimationStep;//20 animation steps

    //animate the Bitmap
    Matrix  mxTransform = new Matrix();
    if (iCurStep <= iMaxAnimationStep) 
    {          

        pm.getMatrix(fSegmentLen * iCurStep, mxTransform,
                PathMeasure.POSITION_MATRIX_FLAG);
        mxTransform.preTranslate(-Bitmap.getWidth(), -Bitmap.getHeight());


       canvas.drawBitmap(Bitmap, mxTransform, null);

        iCurStep++; //advance to the next step
        mPauseViewHandler.post(mPauseViewRunnable);
    } else {
        iCurStep = 0;

    } 

But My Problem is I want to Move This ViewObject(Bitmap) On Dynamic Path(in parabola curve) & that Dynamic curved path will work in Any Device.

I have searched Lot but i can't Find Solution How to get Dynamic Path (in parabola curve).

help! If you have Any Solution,Suggestion, idea ,tutorial regarding this post is Mostly Appreciated.

share|improve this question
    
You may want to clarify your question, as it seems unclear at the moment. –  Nick Caplinger Jun 11 '13 at 22:23
add comment

3 Answers

If I understand your question correctly, you're looking for a damped harmonic function which would be something along the lines of f(x)=e^x*sin(x). In this function x would be time and it would give you the vertical acceleration of the bounce.

An example of an optimized version of the function to your situation might be An example of an optimized version of the function to your situation might be ![ (replaced x with t for time) which would result in the graph of: enter image description here

At f(0), the function will return 1 or the full "force" of the bounce. You cannot have a -delta_time the function has a limited domain of t >= 0 so the function always returns a number between -1 and 1 so you can use it as a scalar for a velocity.

If you just want the height of a bounce just get the absolute value so it becomes enter image description here which will look like:

enter image description here

This is a scalar from 0-1 so just multiply it by the height: enter image description here

Images courtesy of Wolfram Alpha

share|improve this answer
    
thanks for ur answer that better understand physics behind this question. –  Dixit Patel Jun 12 '13 at 6:11
    
That looks cool, but it isn't physically correct. The waves you got there are no parabolas, is are damped sine functions. To be correct, it should have parabolas, in order to get a realistic gravitation effect. –  Martijn Courteaux Jun 15 '13 at 13:31
    
@MartijnCourteaux - They are making a simple animation not a physics simulation clearly. –  stas Jun 17 '13 at 0:27
add comment

I would recommend looking at Box2D. It is a physical engine that will take care of all the physics your game needs. However, if you think this engine is an overkill, just write the simple bouncing mechanism yourself.

Create a vector acceleration, a vector velocity and a vector position. Then on each frame you use the formula's found by integration. Assume step is your timestep in seconds (which is probably something like 1/60).

position += integral(velocity, 0, step), where
velocity += integral(acceleration, 0, step), where
acceleration = (0, -9.81).

So substitute these things in each other gives:

velocity += integral(acceleration, 0, step);
vector velocity0 = velocity;
velocity = velocity0 + vector(acceleration.x * step, acceleration.y * step);

The same for position:

position += integral(velocity, step)
position += integral(velocity0 + vector(acceleration.x * step, acceleration.y * step), 0, step)
position += vector(velocity0.x * step + 0.5 * acceleration.x * step * step, velocity0.y * step + 0.5 * acceleration.x * step * step);

So the code you have to apply each frame is:

vector velocity0 = velocity;
velocity += vector(acceleration.x * step, acceleration.y * step);
position += vector(velocity0.x * step + 0.5 * acceleration.x * step * step, velocity0.y * step + 0.5 * acceleration.y * step * step);

Now, to bounce, just check when position.y < 0. If that happens, do this:

velocity = vector(velocity.x, -velocity.y * restitution)
position.y = 0

Where restitution is a factor between 0 and 1. A normal value would be like 0.6.

share|improve this answer
    
thanks for your answer but i don't have to use other game engine –  Dixit Patel Jun 12 '13 at 6:09
    
Just keep reading. Only the first sentence of my answer was referring to a physics engine. The whole other part is about doing it yourself. –  Martijn Courteaux Jun 15 '13 at 13:32
add comment

Go with simple kinematics. after every bounce the velocity that the entity collided with becomes the initial velocity for the next move. The entity moves in a parabola because of acceleration due to gravity, repeat until many times as necessary. For different curve shapes(more narrow or wider) experiment with direction and velocity at which the object moves.

share|improve this answer
add comment

protected by Community Jun 14 '13 at 9:40

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.