Edges and Collisions

Another way to affect movement with sprites is through the blocks that control edges and collisions.

In the Flick app, we used the whenEdgeReached block to tell the ball to bounce off the edges.

A similar effect is used for collisions. Given that many games have collisions, this kind of permission comes in handy. Event handlers in the ImageSprite and the ball report when sprites collide with each other on the canvas and let you handle that collision however you want. If you specify nothing, they will pass through each other. The “collision” still happens, but no behavior change occurs. You must specify any behavior change you want, and it can be whatever you like.

Get Learning MIT App Inventor: A Hands-On Guide to Building Your Own Android Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.