Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 8, 2012, 10:58:11 PM (12 years ago)
Author:
jo
Message:

Rough example on how to add sound to existing orxonox objects. A Worldsound (sound with phydical location in the level) is played when the player is using a portal. The sound file path has to be adjusted. The current behaviour is that only that portal which is ejecting objects is playing a sound.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/soundEffects/src/modules/portals/PortalEndPoint.cc

    r8767 r9437  
    2828
    2929#include "PortalEndPoint.h"
     30#include "portals/PortalLink.h"
    3031
    3132#include <ctime>
     
    3536
    3637#include "worldentities/MobileEntity.h"
    37 
    3838#include "objects/triggers/MultiTriggerContainer.h"
    3939
    40 #include "portals/PortalLink.h"
     40#include "sound/WorldSound.h"
    4141
    4242namespace orxonox
     
    5959        this->setRadarObjectShape(RadarViewable::Dot);
    6060        this->setRadarVisibility(true);
     61        if( GameMode::isMaster() )
     62        {
     63            this->portalSound_ = new WorldSound(this);
     64            this->portalSound_->setLooping(false);
     65            this->attach(this->portalSound_);
     66            this->portalSound_->setSource("sounds/Weapon_HsW01.ogg"); //TODO: change sound file
     67        }
    6168    }
    6269
    6370    PortalEndPoint::~PortalEndPoint()
    6471    {
    65         if(this->isInitialized() && this->trigger_ != NULL)
    66             delete this->trigger_;
     72        if (this->isInitialized())
     73        {
     74            if (this->portalSound_ != NULL)
     75                this->portalSound_->destroy();
     76
     77            if (this->trigger_ != NULL)
     78                delete this->trigger_;
     79        }
    6780    }
    6881
     
    158171        entity->rotate(this->getWorldOrientation());
    159172        entity->setVelocity(this->getWorldOrientation() * entity->getVelocity());
     173        //play Sound
     174        if( this->portalSound_ && !(this->portalSound_->isPlaying()))
     175        {
     176            this->portalSound_->play();
     177        }
    160178    }
    161179
Note: See TracChangeset for help on using the changeset viewer.