Book Image

Learning Cocos2d-JS Game Development

By : Emanuele Feronato
Book Image

Learning Cocos2d-JS Game Development

By: Emanuele Feronato

Overview of this book

Table of Contents (18 chapters)
Learning Cocos2d-JS Game Development
Credits
Foreword
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Creating Your Own Blockbuster Game – A Complete Match 3 Game
Index

Asteroid versus spaceship collision


The easiest way to see whether two sprites collide, which is also the most used in simple fast paced arcade games like the one you are currently building, is by checking whether sprite bounding boxes intersect somehow.

The bounding box of an image is the smallest rectangle, which entirely contains the image itself, and the principle of this method can be explained by the following image:

In this 4x zoomed image, you can see the three different ways the bounding box collision will react:

  1. Bounding boxes do not intersect. There is no collision.

  2. Bounding boxes intersect. There is a collision.

  3. Bounding boxes intersect, although there isn't a collision.

In sophisticated collision engines, to prevent case 3, once bounding boxes intersect, a pixel perfect collision is performed, but this is CPU-consuming and at the moment, you don't want such a high level of precision.

So, if you want to make case 3 occur as seldom as possible, you can draw your sprites with shapes as...