Questions and Answers Already Passed
What is the purpose of the `drawImage()` function in animation?
✔✔The `drawImage()` function is used to display an image on the canvas at specified
coordinates.
How do you make an object move across the screen in animation?
✔✔You can move an object by updating its position in each frame using variables and redrawing
it in the new position.
What is a sprite in animation?
✔✔A sprite is an image or character used in a game or animation that can be manipulated and
moved.
What is the `clear()` function used for in animation?
✔✔The `clear()` function is used to clear the canvas, typically before drawing a new frame.
How do you control the speed of an animation?
1
,✔✔You control the speed of an animation by adjusting the delay between frames, often using
`setInterval()` or `requestAnimationFrame()`.
What is the purpose of the `fillRect()` function in animation?
✔✔The `fillRect()` function is used to draw a filled rectangle on the canvas at specified
coordinates.
What is a frame in animation?
✔✔A frame is a single image in a sequence of images that make up an animation.
How do you create a bouncing effect in animation?
✔✔You create a bouncing effect by reversing the direction of an object when it reaches the edge
of the screen.
What is a collision detection in game development?
✔✔Collision detection is the process of determining if two or more objects in a game have
collided.
How do you move a character in a game using keyboard input?
2
,✔✔You can move a character by listening for keyboard events using `keydown` or `keyup`
events and adjusting the character’s position accordingly.
What is the role of `requestAnimationFrame()` in animations?
✔✔`requestAnimationFrame()` is used to schedule the next frame of an animation, providing a
smoother and more efficient animation loop.
What is the `keyCode` property used for in games?
✔✔The `keyCode` property is used to detect which key was pressed on the keyboard.
What is the purpose of `beginPath()` in the HTML5 canvas API?
✔✔The `beginPath()` function starts a new path, allowing you to define a shape or line before
drawing it.
What is the difference between `fill()` and `stroke()` in drawing shapes?
✔✔`fill()` fills the interior of a shape with color, while `stroke()` draws the outline of the shape.
How do you change the background color of the canvas in animation?
3
, ✔✔You can change the background color by using the `fillStyle` property and drawing a
rectangle that covers the entire canvas.
What is the `moveTo()` function used for in animation?
✔✔The `moveTo()` function is used to move the pen to a new starting position on the canvas
without drawing anything.
What is the purpose of `setInterval()` in animation?
✔✔`setInterval()` is used to call a function at specified intervals, allowing you to create repeated
actions like animation loops.
How do you make an object rotate in animation?
✔✔You can make an object rotate by adjusting its rotation angle and using the `rotate()` function
in each frame.
What is the role of `fillStyle` in drawing shapes?
✔✔The `fillStyle` property sets the color or style to be used for filling shapes on the canvas.
How do you handle user input in games?
4