



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Why do you use an ImageSheet when creating sprites? ImageSheets allow the sprites to be animated. An ImageSheet is used to create an animated sprite. The ImageSheet can be updated to rapidly change the picture and create an animation. Which of the following would be a valid sprite image(s) for our program? plane.gif plane.png plane.tiff plane.jpg plane.png and plane.jpg Only .jpg and .png files can used as image files in our system. .jpg files are smaller, but do not support transparency like .png files do. To create a sprite you need 3 provide 3 arguments. What are the 3 arguments? filename, left, top The function to create a Sprite comes from the tsk library, and takes 3 arguments: the filename, the x location of the left, and the y location of the top. Width and height are decided automatically from the image file used. Using the following code, which sprite will appear in the front? mountain.draw() tree.draw() rabbit.draw() pygame.display.flip()
rabbit The order that sprites appear is based on the order in which they're drawn, not created. Sprites drawn later will draw on top of sprites drawn earlier. Using the following code, which sprite will appear in the back? mountain.draw() tree.draw() rabbit.draw() pygame.display.flip() mountain The order that sprites appear is based on the order in which they're drawn, not created. Sprites drawn later will draw on top of sprites drawn earlier. In the following code, what represents the distance the sprite travels in each frame? plane = tsk.Sprite("Airplane.png", 0, 300) plane.center_x = 0 while drawing: plane.center_x += .8 * c.get_time() background.draw() plane.draw() pygame.display.flip() c.tick(30) .8 * c.get_time() When moving a sprite, we multiply it by c.get_time() to keep its speed consistent across all computers. Using the following code, what is the starting location of the sprite? plane = tsk.Sprite("Airplane.png", 0, 300) plane.center_x = 0 while drawing: plane.center_x += .8 * c.get_time() background.draw() plane.draw()
Using the following code, indicate what can be multiplied with speed to move a sprite at the same speed on all computers. plane = tsk.Sprite("Airplane.png", 0, 300) plane.center_x = 0 while drawing: plane.center_x += .8 * c.get_time() background.draw() plane.draw() pygame.display.flip() c.tick(30) plane.center_x += .8 * c.get_time() In order to run smoothly on different computers, the movement of the sprite should be based on the framerate of the program. We can do this by multiplying the speed by the duration of the previous frame. Which set of codes indicates the correct way to code a ImageSheet?
sheet = tsk.Imagesheet("Airplane.png", 5, 6) plane. = tsk.Sprite(sheet, 500, 400)
sheet = tsk.Imagesheet("Airplane.png", 5, 6) plane. = tsk.Sprite("Airplane.png", 500, 400)
To use an ImageSheet as a sprite's image, use the ImageSheet variable where you would normally put the filename for the image. What line of code would you use to animate a sprite? sprite.update(c.get_time()) An ImageSheet must be updated in order for the images to cycle through. Otherwise it will just stay on its current frame. How do we determine if two sprites have collided? Rectangle collision
Sprites are surrounded by an invisible rectangle based on their size. We use these rectangles to see when two sprites collide - meaning they overlap. How do we determine if a sprite has collided with a location? Point collision Point collision says whether a given point is over the rectangle for a sprite. The most common case is checking the location of the mouse pointer. What are sprite walls? Sprite walls are used to stop a sprite by moving the sprite backward when it collides with the wall. In the following code, what is the number that represents the distance between each sprite in the row. for i in range(10): x = 100 + i * 50 icon = tsk.Sprite("BlankIcon.png", x, 150) icons.append(icon) 50 When creating a row of sprites, we use this formula: left margin + i * distance. Left margin is the distance between the edge of the screen and the first sprite, i is the iteration of the loop, and distance is how far between sprites. Which point is being checked for collision with the rabbit sprite? (Give your answer as a tuple.) balloon = tsk.Sprite("balloon.png", 0, 0) while drawing: cloud.center_x += .1 * c.get_time() balloon.center = pygame.mouse.get_pos() if balloon.rect.collidepoint(400, 350): print("Go!") (400, 350) The collidepoint function tests whether a sprite collides with a specific point. It is called on a specific sprite, and takes the x and y of the point as arguments. How can you tell if a sprite has been clicked? In order for the user to click on a sprite they must click the mouse WHILE the mouse pointer is over the sprite. Only if both are true was the sprite clicked.
How many sprites will be drawn using the code below? birds = [robin, bluebird, owl, hawk, blue bird, peacock] for bird in birds: bird.draw() 6 A list of sprites can be drawn in one step by going through each item in the list with a for-loop. What is the most important thing to remember when drawing sprites using a list? Remember to put the sprites in the order that they should be drawn.