Skip to content

04 Adding a Behaviour

Robert Silverton edited this page Jul 8, 2014 · 4 revisions

Currently the scene you have made in the previous tutorials is a little dull, so let’s make things a bit more interesting and add a physics behaviour.

In the scene1.cdt2d file in your open instance of FlashBuilder, select “Rectangle_0” in the Outline panel. Now in the ToolBar at the top of the Outline panel, click the “Add Component...” button. The Add Component dialogue is opened and Rectangle_0 is selected in the scene outline on the left. Notice when you click through the tabs on the right that the various options are context sensitive, for example Processes cannot be added to your ComponentContainer (when Rectangle_0 is the highlighted node in the scene outline).

Make sure "Rectangle_0" is selected, then in the Behaviours tab, select RigidBody and below the Behaviour options press the “<<” button to add it to your scene. You should now see on the left that the RigidBody behaviour has been added to the scene as a child of your Rectangle_0 Component. Press “OK” to keep your changes, save the scene and select “Project/Build and Run”.


Nothing happens... The rectangle didn't move. Why not? This is because although you've added a RigidBody behaviour to your Rectangle_0 Component, you haven’t added a Physics process to your scene. This is the equivalent of adding a GeometrySkin to your object but not adding a Renderer2D to the scene, the Component is saying “draw me like this!” but there isn't a Render to listen to and process that instruction.

Close the CadetViewer window (“File/Close”), and select “Add Component...” again in the Outline panel. Make sure to select the root “scene” node in the add component dialogue, and then in the Processes tab, select Physics and add it to your scene. Save your scene and Build and Run. You should now see the rectangle drop off the bottom of the screen.


< Previous