Creating your own Sprite
As you go about developing different types of games, you may find that you need to store some more information regarding the entities or objects in your game. Such a situation has arisen for this particular game as well. For SpaceCraze, we will need to manipulate the size of each of our entities' sprites: player, enemy and brick. In addition to size, we will also need to manipulate the boundingBox
function. Why do we need to change the bounding box you wonder? Just take a look at a shot of the player's sprite frame shown here:
Notice how the texture here includes a shadow for styling. This would cause the bounding box for the player's sprite to include the shadow. Consequently, our collisions would look visually incorrect with the player getting shot without the enemy bullet actually making contact with the body of the player's ship.
So without further ado, let's get to the header file of the class that we shall conveniently name CustomSprite...