Verschiedene Motorsounds auf Tastendruck

  • Hallo,


    ich bin dabei einen Bagger für LS zu bauen.
    Ich möchte das beim bedienen des Auslegers der Sound wechselt (wird der Ausleger nicht bewegt hört man den normalen Motorsound, wird der Ausleger bewegt sollte der "Motorsound" verstummen und der "Motorworksound" zu hören sein).
    Mir ist es bereits gelungen den Motorsound zu unterbrechen und beim bewegen des Auslegers hört man auch den Motorworksound.
    Jedoch startet danach der Motorsound nicht wieder.


    Könnt ihr mir vielleicht weiterhelfen?


    Hier mal ein Auszug der LUA:[lua]
    function motor:load(xmlFile)


    motorworkSoundFile = Utils.getFilename("Sounds/work_sound.wav", self.baseDirectory);
    self.motorworkSoundId = createSample("motorworkSound");
    loadSample(self.motorworkSoundId, motorworkSoundFile, false);
    self.motorworkPlaying = false;
    self.motorworkSoundAllow = false;
    end;




    function motor:update(dt)


    if Input.isKeyPressed(Input.KEY_KP_1) or
    Input.isKeyPressed(Input.KEY_KP_2) or
    Input.isKeyPressed(Input.KEY_KP_3) or
    Input.isKeyPressed(Input.KEY_KP_4) or
    Input.isKeyPressed(Input.KEY_KP_5) or
    Input.isKeyPressed(Input.KEY_KP_6) or
    Input.isKeyPressed(Input.KEY_KP_7) or
    Input.isKeyPressed(Input.KEY_KP_8) or
    Input.isKeyPressed(Input.KEY_KP_9) or
    Input.isKeyPressed(Input.KEY_KP_0) then
    self.motorworkSoundAllow = true;
    if not self.motorworkPlaying then
    stopSample(self.motorSound);
    playSample(self.motorworkSoundId,0,1,0);
    self.motorworkPlaying = true;
    end;
    elseif self.motorworkPlaying then
    playSample(self.motorSound);
    stopSample(self.motorworkSoundId);
    self.motorworkPlaying = false;
    end;
    end;[/lua]

  • moin also du musst das soweit ich das sehe so um ändern


    [lua]
    function motor:load(xmlFile)


    motorworkSoundFile = Utils.getFilename("Sounds/work_sound.wav", self.baseDirectory);
    self.motorworkSoundId = createSample("motorworkSound");
    loadSample(self.motorworkSoundId, motorworkSoundFile, false);
    self.motorworkPlaying = false;
    self.motorworkSoundAllow = false;
    end;




    function motor:update(dt)


    if Input.isKeyPressed(Input.KEY_KP_1) or
    Input.isKeyPressed(Input.KEY_KP_2) or
    Input.isKeyPressed(Input.KEY_KP_3) or
    Input.isKeyPressed(Input.KEY_KP_4) or
    Input.isKeyPressed(Input.KEY_KP_5) or
    Input.isKeyPressed(Input.KEY_KP_6) or
    Input.isKeyPressed(Input.KEY_KP_7) or
    Input.isKeyPressed(Input.KEY_KP_8) or
    Input.isKeyPressed(Input.KEY_KP_9) or
    Input.isKeyPressed(Input.KEY_KP_0) then
    if self.workactive = not self.workactive ; // Irgendeine Variable


    if self.workactive then
    playSample(self.motorSound);
    stopSample(self.motorworkSoundId);
    self.motorworkPlaying = false;
    end;


    else
    stopSample(self.motorSound);
    playSample(self.motorworkSoundId,0,1,0);
    self.motorworkPlaying = true;
    end;


    end;
    [/lua]

  • Problem gelöst, self.playMotorSound = true; eingefügt.


    Trotzdem danke für eure Hilfe. :thumbup:


    [lua]if self.isEntered then
    if Input.isKeyPressed(Input.KEY_KP_1) or
    Input.isKeyPressed(Input.KEY_KP_2) or
    Input.isKeyPressed(Input.KEY_KP_3) or
    Input.isKeyPressed(Input.KEY_KP_4) or
    Input.isKeyPressed(Input.KEY_KP_5) or
    Input.isKeyPressed(Input.KEY_KP_6) or
    Input.isKeyPressed(Input.KEY_KP_7) or
    Input.isKeyPressed(Input.KEY_KP_8) or
    Input.isKeyPressed(Input.KEY_KP_9) or
    Input.isKeyPressed(Input.KEY_KP_0) then
    self.motorworkSoundAllow = true;
    if not self.motorworkPlaying then
    stopSample(self.motorSound);
    playSample(self.motorworkSoundId,0,1,0);
    self.motorworkPlaying = true;
    end;
    elseif self.motorworkPlaying then
    playSample(self.motorSound);
    stopSample(self.motorworkSoundId);
    self.motorworkPlaying = false;
    self.playMotorSound = true;
    end;
    end;
    end;[/lua]

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!