Have a look at the program below. It should all be pretty familiar stuff:
- An HTML wrapper, and a canvas
- A ctx variable, which is our drawing context for the canvas
- An FPS variable, where we hold our desired number of frames per second
- A MySprite object, with x and y properties, and velocity properties
- A Do_Frame_Things method of MySprite, that updates the position according to the velocity and draws the image
- A variable called MyBall, which is a MySprite and is an image of a tennis ball
- A frame renderer called Do_a_Frame that clears the canvas and then calls MyBall.Do_Frame_Things
- A timer that calls Do_a_Frame repeatedly, according to FPS
Because we haven't made it do anything else yet, the ball just sits motionless with it's top-left corner positioned at x=0 y=0.