About Physics

Physics in SwinGame is used to check collisions between objects as well as perform collisions between objects.  


Level

Beginner

Details


Basics of Physics

In SwinGame functions called _____Collision will return either True or False, depending on if the two objects have collided. While the procedures called Collide______ will perform a collision and bounce the two objects off each other.


Vectors

A vector describes how far, and in what direction to move an object. When a vector is applied to a position the x value of the vector is added to the x value of the position and the y value of the vector is added to the y value of the position.


Shape Collisions

Checking collisions between shapes and sprites is done by checking if part of one shape is inside the other shape, this is used for approximate collision checking and is much faster than pixel level collision checking. This kind of collision checking should be used if accuracy is not important.



Bitmap Collisions

Bitmap collisions use both shape collision checking and pixel level collision checking. Shape checking is performed first to ensure that pixel level checking is required, then the pixel level checking is performed.

Pixel level checking makes sure that the bitmap doesn't have any opaque pixels overlapping with the shape or bitmap it is being compared to.


Pixels in your bitmap that are not completely transparent will cause a collision



Sprite Collisions

Sprites can use two kinds of collision checking, they can use either shape checking, or pixel testing. By default Sprites will use shape checking because it is fastest, however you can set the CollisionKind of a sprite use SpriteSetCollisionKind. The two options are AABBCollisions, or PixelCollisions.