【问题标题】:ChucK Joystick ControlChuck 操纵杆控制
【发布时间】:2016-03-07 03:38:12
【问题描述】:

我正在尝试接收来自操纵杆的输入。收到输入后 应产生声音。这有效,但它响应操纵杆按钮的按下和释放。如何让它只响应推送而不响应发布。

更重要的是,如何让事件侦听器响应操纵杆的 180 度移动。目前,当我移动操纵杆时,它继续产生声音,即使在我释放它很久之后

 Hid myHid;

HidMsg msg;

0=>int device;

if(!myHid.openJoystick(device)){
<<<"Couldn't">>>;
me.exit();
}

<<<"Ready">>>;

SndBuf coin=>dac;
  0.6=>coin.gain;
0=>coin.pos;



while(1){

    myHid=>now;
    while(myHid.recv(msg)){
        <<<"Rev">>>;

        me.dir()+"/audio/smw_jump.wav"=> coin.read;
        .2::second=>now;


        }

    }

【问题讨论】:

    标签: events input joystick chuck


    【解决方案1】:
      // make HidIn and HidMsg
          Hid hi;
        HidMsg msg;
    
       SndBuf jump=>dac;
      SndBuf coin=>dac;
     SndBuf power_up=>dac;
      SndBuf blaster=>dac;
    
    
    0.85=>coin.gain;
    0=>coin.pos;
    
    .6=>jump.gain;
     0=>jump.pos;
    
    .85=>power_up.gain;
    0=>power_up.pos;
    
    .6=>blaster.gain;
    0=>blaster.pos;
    
     // which joystick
      0 => int device;
     // get from command line
     if( me.args() ) me.arg(0) => Std.atoi => device;
    
     // open joystick 0, exit on fail
     if( !hi.openJoystick( device ) ) me.exit();
    
    <<< "joystick '" + hi.name() + "' ready", "" >>>;
    
     // infinite event loop
      while( true )
     {
    // wait on HidIn as event
    hi => now;
    
    // messages received
    while( hi.recv( msg ) )
    {
        // joystick axis motion
        if( msg.isAxisMotion() )
        {
    
            //this is where we pan
            <<< "joystick axis", msg.which, ":", msg.axisPosition >>>;
            // OR
            //if (msg.which == 0) <<< "joystick axis", msg.which, ":",    msg.axisPosition >>>;
            //if (msg.which == 1) <<< "joystick axis", msg.which, ":", msg.axisPosition >>>;
        }
    
        // joystick button down
        else if( msg.isButtonDown() )
        {
    
            <<< "joystick button", msg.which, "down" >>>;
    
            if(msg.which==0){
                me.dir()+"/audio/Laser Blasts-SoundBible.com-108608437.wav"=> blaster.read;
            .2::second=>now;
    
                }
    
                if(msg.which==4 || msg.which==2 ||msg.which==3 ||msg.which==5){
                    me.dir()+"/audio/smw_coin.wav"=> jump.read;
                    .2::second=>now;
                }
    
        }
    
        // joystick button up
        else if( msg.isButtonUp() )
        {
            <<< "joystick button", msg.which, "up" >>>;
        }
    
        // joystick hat/POV switch/d-pad motion
        else if( msg.isHatMotion()  && msg.idata==0)
        {
            <<< "joystick hat", msg.which, ":", msg.idata >>>;
            me.dir()+"/audio/smb_powerup.wav"=> power_up.read;
                    .2::second=>now;
    
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多