Colliding One Object with Another

From Documentation
Jump to: navigation, search

Colliding One Object with Another

This example demonstrates a drag action, collision detection, and custom messages, where dragging one object into another makes the second object fly off the page.

  1. In Page view, add two objects to the page.
  2. Make sure the first object (the one you plan to drag) is in front of the second object.
  3. Make a note of each object's ID as it appears on the Action tab of the properties panel.
  4. Select the first object and create a custom message named FlyAway, as described in Tailoring Actions with Custom Messages. Create an action to use in creating the custom message and then delete it.
  5. Add an action to the first object (as described in Adding Actions to Objects and Pages) so that mousing down on it makes it stick to the pointer until you mouse up.

In the Set Action dialog, enter Mouse, Mouse Down in the When field; the first object in the Target field; Drag, Start Drag in the Message field; and Until Mouse Up in the Parameters field.

  1. Add a collision detection action to the first object like this:

In the Set Action dialog, enter Page, Page Loaded in the When field; the first object in the Target field; and Drag, Set Collision Detection in the Message field. Then open the Values dialog from the Parameters menu and specify the second object for the Object ID value (type the object's ID exactly as it appears on the Actions tab of its properties panel), and enter FlyAway for the Message value. When the first object is dropped over the second, it sends the FlyAway message to the first object.

  1. Add yet another action to the first object that's triggered by the FlyAway message and tells the second object to fly off the page.

In the Set Action dialog, enter Custom, FlyAway in the When field; the second object in the Target field; Motion, Fly in the Message field; and Out To Top in the Parameters field.

Then preview the page to test your collision. Drag the first object over the second, drop it there, and watch the second object fly off the page.