首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ChucK操纵杆控件

ChucK操纵杆控件
EN

Stack Overflow用户
提问于 2015-12-03 02:39:44
回答 1查看 121关注 0票数 1

我正在尝试接收来自操纵杆的输入。在接收到输入之后,应该会生成声音。这是有效的,但它对按下和释放操纵杆的按钮都有反应。我如何让它只响应推送而不响应释放。

更重要的是,我如何让事件侦听器对操纵杆的180度移动做出响应。目前,当我移动操纵杆时,它会继续发出声音,即使在我释放它很长时间之后也是如此

代码语言:javascript
复制
 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;


        }

    }
EN

回答 1

Stack Overflow用户

发布于 2015-12-03 09:13:57

代码语言:javascript
复制
  // 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;

    }
}
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34050487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档