Adding gravity to sprites in canvas

I am making a game which the goal is when the user clicks the button, a ball (which is the imageSprite, not the preloaded ball) will move up, generally naturally, and back down with the looks of a gravitational pull. how would i be able to do that without it being glitchy? also ball cannot touch the edges of the canvas or game over.

the only thing I can find is pointInDirection, but it would point the ball and not move it. i think rotate and speed would have to be involved? can i get help on how to implement this

thanks
makaya

also, how would i be able to toggle a countdown when the start button is pressed, in relation to the ball moving? gravity would have to be implemented first, obviously, but the if-then would be complex ?

See the third link in

See the second link in

would you be able to explain the code blocks in the 2nd link? also how would i be able to keep the ball in the air, as that is another problem.

Please read the chapter on doing animated apps in
http://www.appinventor.org/book2

and do a couple of the animation tutorials.

okay, thank you. will do.

would i need to include velocity if the movement is only up and down, or only include speed?

Velocity is the combination of speed and direction, by definition.

Where did you see the term velocity used?

here, in the first redirect you gave me. i am also using that as guidance.

this is what i have right now

Try using two global variables, ballSpeedX and ballSpeedY.

Let gravity affect ballSpeedY.

In that case, would I delete the variable ballSpeed altogether, or would I need a separate speed variable as well? sorry, I'm new to this I'm just trying to understand the best I can

This is from

Notice how the X and Y are changed separately, under different influences.

so change that in my updateBallPos procedure? that has the most similar code there

Sure, try it.

You're allowed and encouraged to experiment.

1 Like