Enable Devices to Interact with Sprites

In addition to separate programming for devices and sprites, mBlock 5 also supports the interaction between devices and sprites. By using the broadcast message blocks, you can enable a device to interact with a sprite, which brings more interesting effects.

In the programs described in previous sections, we have created a bee and added a sound and costume for it, and programmed HaloCode. Now, let's try to enable HaloCode to interact with the bee.

Now, try to complete the following task: When you press the blue button on HaloCode, the bee on the stage moves.

Program the Device

(1) Drag the Events block when button is pressed to the Scripts area.

(2) Drag the Events block broadcast ( ) to the Scripts area.

(3) Create a new message. You can set a name for the new message to help identify it. In this case, let's name it Make it move.

Program the Sprite

(1) Continue to compile the program described in Add Sounds and Costumes. Drag when green flag clicked back to the Blocks area to delete it.

(2) Drag the Events block when I receive ( ) to the Scripts area and choose the message Make it move.

(3) Press the blue button on HaloCode and see what happens.

For more details about how to enable devices to interact with sprites, see Interact with Sprites .

results matching ""

    No results matching ""