views:

172

answers:

1

I would like to move a sphere in a random direction within a simple universe. How could i achieve this with behaviours by changing the location a small amount frame by frame. The reason I am trying to do this is to produce random movement within the universe and eventually build in simple collision detection between the particles.

Any advice/links would be appreciated

A: 

Add a new class that extends Behavior, using this skeleton:

public class XXXBehavior extends Behavior
{
    private WakeupCondition wc = new WakeupOnElapsedTimer(1000); // 1000 ms

    public void initialize()
    {
        wakeupOn(wc);
    }

    public void processStimulus(Enumeration criteria)
    {
        // Move the shape here

        // prepare for the next update
        wakeupOn(wc);
    }
}

You later need to instantiate the class and add it to the scene graph. You also need to defined the bounds, otherwise nothing will happen!

xxxEffect = new XXXBehavior();
xxxEffect.setSchedulingBounds(bounds);
sceneBG.addChild(xxxEffect);