Video Game Design and Programming Concepts 42 Copyright Goodheart-Willcox Co., Inc. May not be reproduced or posted to a publicly accessible website. 43. Applying what you have learned, run the frame to see what happens. Close the game window when done. Collision Detection As you could see when you tested the frame, the tennis ball moves through the walls and off the screen. This is because collision detection has not been programmed. The walls are not real walls, they are just colored pixels. The wall objects must have programming so the computer will treat them as real walls. Collision detection is how the computer recognizes when one object has touched another. The designer can specify to have the collision detected by the bounding box for the object or by the object’s edge as defined by the pixels of the sprite. Refer to Figure 3-5. For rectangular objects like the walls, the bounding box would be used. A bounding box is a rectangular region within which the sprite on object fits. For nonrectangular objects like the ball, the object edge would be used. Run Frame Set the type of movement Set the speed Check Goodheart-Willcox Publisher Figure 3-4. To make the ball object act like a ball, the movement is set to the bouncing ball type. Bounding box Object edge Goodheart-Willcox Publisher Figure 3-5. Collision detection can be based on an object’s bounding box or the edge of the object.
Previous Page Next Page