Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  WakeupOnBehaviorPost  (Read 777 times)
0 Members and 1 Guest are viewing this topic.
Offline esvxm

Senior Newbie




Java games rock!


« Posted 2004-02-11 22:12:25 »

Hi!

Can any one explain how WakeupOnBehavior works, a code snippet would be very helpful and would be ok to use it for a character animation to synchronise the movements of varioius limbs

Thanks
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #1 - Posted 2004-02-13 04:05:18 »

 In a game project, I used Behavior posts to comunicate the Movement Behavior (wakeuponAWTEvent) with the bullet Animation Behavior (wakeupOnEllapsedTime).
 In my case, I called the constructor setting the Behavior to listen.
 When the player press the fire/attack button the Movement Behavior posts an id indicating to the bullet animation Behavior to start its animation/simulation.
 When the bullet hits something the Animation Behavior post an id indicating wich object was hit.

 Now the code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
class BulletAnim extends Behavior{
  ...
  private WakeupOr wor;
  private WakeupOnBehaviorPost waiting;
  public BulletAnim(...){
    ...
    WakeupCriterion[] criterio = new WakeupCriterion[2];
    criterio[0]= new WakeupOnElapsedTime(1000/60);
    criterio[1]=new WakeupOnCollisionEntry(sphere,WakeupOnCollisionEntry.USE_GEOMETRY);
    wor=new WakeupOr(criterio);
  }
  public void setPartner(Behavior b){
    //Here I set the movement Behavior as the source of the posts.
   //I will receive any id (id == 0).
   waiting = new WakeupOnBehaviorPost(b, 0);
  }
  public void initialize()
  {
    this.wakeupOn(waiting);
  }
  public void processStimulus(Enumeration criteria){
    boolean moving = false;
    while (criteria.hasMoreElements()) {
      WakeupCriterion wakeup = (WakeupCriterion) criteria.nextElement();
      if(wakeup instanceof WakeupOnBehaviorPost){
        //now it wakes up with the time or collision
       moving = true ;
      }
      else if(wakeup instanceof WakeupOnElapsedTime){
        //do the animation
       ...
        moving = true ;
      }
      else if(wakeup instanceof WakeupOnCollisionEntry){
        //get the object hit
       int objectId = ...  //Collision info.
       postId(objectId);  //send the signal to the movement behavior
       moving = false;
      }
    }
    if(moving)
      this.wakeupOn(wor);
    else
      this.wakeupOn(waiting);
  }
}

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
class TankMovement extends Behavior{
  ...
  private WakeupOnAWTEvent trigger;
  private WakeupOnBehaviorPost waiting;
  public TankMovement(...){
    ...
    trigger=new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
  }
  public void setPartner(Behavior b){
    //Here I set the movement Behavior as the source of the posts.
   //I will receive any id (id == 0).
   waiting = new WakeupOnBehaviorPost(b, 0);
  }
  public void initialize()
  {
    this.wakeupOn(trigger);
  }
  public void processStimulus(Enumeration criteria){
    boolean moving = false;
    while (criteria.hasMoreElements()) {
      WakeupCriterion wakeup = (WakeupCriterion) criteria.nextElement();
      if(wakeup instanceof WakeupOnBehaviorPost){
        //now it wakes up returns to receive input
       moving = true ;
      }
      else if(wakeup instanceof WakeupOnAWTEvent){
        //receive and process the input
       ...
        if(shot!=0){
          postId(shot);  //send the signal
         moving = false ;
        }
      }
    }
    if(moving)
      this.wakeupOn(trigger);
    else
      this.wakeupOn(waiting);
  }
}


Then in the scene creation:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
  ...
  BulletAnim anim = new BulletAnim(...);
  ...
  TankMovement tankMove= new TankMovement(...);
  ...
  //set the partners first
 anim.setPartner(tankMove);
  tankMove.setPartner(anim);
  ...
  //then add to the scenegraph
 bg1.addChild(anim);
  bg2.addChild(tankMove);
  ...

 For the character animation, you can use the constructor without Behavior and send signals to all the behaviors, each will know when and how much to move.

 Rafael
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (25 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!