This article will show you how to collide two sprites with each other.
SwinGame has enough physics knowledge to determine the escape angle of a circular sprite if it hits another sprite at a certain angle. To do this you only need to check if the sprites are in collision, and if they are then you just call a function to collide them with each other. To be able to do it, you just need to follow these steps:
- Create two sprites (Create Sprite) Set their initial position (Sprite Set X) and velocity (Sprite Set Velocity). When giving the velocity of the sprites, make sure that they will collide with each other before going off the screen.
- In the game loop check if the sprites are in collision (Sprite Collision), if they are then call the function Collide Circles and pass both sprites as parameters. This function will help you to collide the sprites with each other.
The code below shows a small program that demonstrates all these steps for colliding two sprites with each other.