tutorials.de Buch-Aktion 05/2012
ERLEDIGT
JA
ANTWORTEN
1
ZUGRIFFE
282
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Registriert seit
    Jun 2008
    Ort
    Nah bei Köln
    Beiträge
    252
    Hallo,

    wollte einen Button programmieren der mir ermittelt welcher Joystick Knopf gedrückt wird, sobald einer gedrückt wird. So wie in den Spielen halt, wenn man z.B. definiert auf welcher Taste die Hupe liegt.

    Sieht bis jetzt so aus:

    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
    47
    48
    49
    50
    
    // Find all the GameControl devices that are attached.
        DeviceList^ conList = Manager::GetDevices(DeviceClass::GameControl,  EnumDevicesFlags::AttachedOnly);
                     
    // check that we have at least one device.
        if(conList->Count > 0){
                conList->MoveNext();
                DeviceInstance^ devInst = (DeviceInstance)conList->Current;
                Device^ joy =  gcnew Device(devInst->InstanceGuid);
                joy->SetCooperativeLevel(this, CooperativeLevelFlags::Background | CooperativeLevelFlags::NonExclusive);
                joy->SetDataFormat(DeviceDataFormat::Joystick); 
            // Finally, acquire the device.
                joy->Acquire();
                DeviceCaps cps = joy->Caps;
                
            // Name of JoyStick
                MessageBox::Show("Chosen Device: " + joy->DeviceInformation.ProductName);
            // number of Axes
                MessageBox::Show("Joystick Axis: " + cps.NumberAxes);
            // number of Buttons
                MessageBox::Show("Joystick Buttons: " + cps.NumberButtons);
            // number of PoV hats
                MessageBox::Show("Joystick PoV hats: " + cps.NumberPointOfViews);
                            
            try
            {
                     joy->Poll();
                     // update the joystick state field
                    JoystickState state = joy->CurrentJoystickState;
                             
                 // cli::array<bool>^ buttons = gcnew array< bool>(joy->Caps.NumberButtons);
                     bool pressed = false;
                     while(!pressed){
                        for(int i = 0; i < joy->Caps.NumberButtons; i++){
                            state = joy->CurrentJoystickState;
                                    if(state.GetButtons()[i] >= 128){
                                pressed = true;
                                MessageBox::Show("Blubb");
                            }
                                        
                        }
                                 
                    }
     
                             
                } catch (Exception^ err)  {
                     MessageBox::Show(err->Message);
                 }
                         
     
             }

    Aber sobald er in die while-Schleife geht ist Ende - Endlosschleife
    Ich denke es ist die Zeile:

    Code :
    1
    
     if(state.GetButtons()[i] >= 128){

    Aber in nem anderen Fall geht die Zeile ohne Probleme...
    da heissts nämlich:

    bool buttonA = state.GetButtons()[0] >= 128;

    und dann kann ich halt if(buttonA){ .... } blubb blah blah machen....

    Bitte helft mir.

    Danke im Vorraus!

    WR
    Geändert von WorldRacer (28.12.08 um 12:21 Uhr)
     

  2. #2
    Registriert seit
    Jun 2008
    Ort
    Nah bei Köln
    Beiträge
    252
    Mein Gott, dass ihr da net drauf kommt...

    Ich hab nun die Lösung selbst gefunden...
    in der while-Schleife zusätzlich noch joy-Poll(); ausführen und schon gehts....
     

Ähnliche Themen

  1. Antworten: 2
    Letzter Beitrag: 03.03.09, 16:15
  2. Antworten: 1
    Letzter Beitrag: 23.05.08, 21:23
  3. Antworten: 8
    Letzter Beitrag: 30.04.06, 16:46
  4. Wert von Radio Button auf einen Submit Button weiterleiten
    Von ImperatorAres im Forum Flash Plattform
    Antworten: 8
    Letzter Beitrag: 20.09.05, 07:19
  5. Antworten: 2
    Letzter Beitrag: 23.11.00, 13:14