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.

Location:
code/branches/soundEffects/src/modules/portals
Files:
2 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
  • code/branches/soundEffects/src/modules/portals/PortalEndPoint.h

    r8767 r9437  
    115115            std::map<MobileEntity *, time_t> jumpOutTimes_;   //!< Stores the time at which a certain MobileEntity @ref jumpOut "jumped out" of this PortalEndPoint
    116116            std::set<MobileEntity *> recentlyJumpedOut_;   //!< Stores the entities witch recently jumped out of this PortalEndPoint and haven't left the activation radius yet. This is needed in order to prevent them from beeing pulled into the PortalEndPoint they have just come out of.
     117
     118            WorldSound* portalSound_;
    117119    };
    118120
Note: See TracChangeset for help on using the changeset viewer.