本文整理汇总了C++中sf::Sound::setBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ Sound::setBuffer方法的具体用法?C++ Sound::setBuffer怎么用?C++ Sound::setBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sound
的用法示例。
在下文中一共展示了Sound::setBuffer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
sf::Sound * SoundsManager::createMusic(sf::Uint8 ID)
{
music.setBuffer(buffers[ID]);
music.setVolume(buffers[ID].defaultVolume * static_cast<float>(musicVolume) / 100.f);
return &music;
}
示例2: init
void init() {
m_first_trip = false;
m_current_state = IDLE;
getBody()->GetFixtureList()->SetUserData("Checkpoint");
getBody()->SetUserData(this);
//Load Texture
s_texture = "Assets/Game/cp_ps.png";
m_text_size = sf::Vector2u(42, 94);
m_sprite.setTexture(ResourceManager<sf::Texture>::instance()->get(s_texture));
m_sprite.setOrigin(m_text_size.x / 2, m_text_size.y / 2);
m_sprite.setPosition(vHelper::toSF(getBody()->GetPosition()));
addFrames(frame_idle, 0, 0, 1, 42, 94, 1.0f);
addFrames(frame_trip, 1, 0, 5, 42, 94, 1.0f);
addFrames(frame_active, 2, 0, 3, 42, 94, 1.0f);
m_animator.addAnimation(IDLE, frame_idle, sf::seconds(1.0f));
m_animator.addAnimation(TRIP, frame_trip, sf::seconds(0.4f));
m_animator.addAnimation(ACTIVE, frame_active, sf::seconds(0.3f));
//Load Audio
s_noise = "Assets/Audio/Game/cp.wav";
m_noise.setBuffer(ResourceManager<sf::SoundBuffer>::instance()->get(s_noise));
}
示例3: init
virtual void init()
{
dt=0;
select_switch = 0.2;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
// darken = sf::RectangleShape(sf::Vector2f(800,400));
//sfx
if (!buffer.loadFromFile("sfx/Blip 007.wav"))
{
//error
}
blip.setBuffer(buffer);
if(!title.loadFromFile("gfx/title.png"))std::cout<<"Error"<<std::endl;
tits.setTexture(title);
tits.setOrigin(50,8);
tits.setScale(sf::Vector2f(3,3));
tits.setPosition(400,100);
sf::FloatRect tempt ;
for(int i =0 ; i<4;i++)
{
selector[i].setFont(standard_font);
selector[i].setCharacterSize(28);
// dla centrowania obiektow
tempt = selector[i].getGlobalBounds();
selector[i].setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
selector[i].setPosition(350,150+30*i);
}
selector[0].setString("Start game");
selector[1].setString("Info");
selector[2].setString("Highscores");
selector[3].setString("Exit");
selector[0].setColor(sf::Color(0,127,127));
timer.restart();
};
示例4: play_sound
void play_sound(sf::Sound& sound, const SoundSample& sample, const PlaybackProperties& properties, bool looped)
{
sound.setBuffer(sample);
sound.setPitch(properties.pitch);
sound.setAttenuation(properties.attenuation);
sound.setLoop(looped);
sound.setRelativeToListener(properties.relative_to_listener);
sound.setMinDistance(properties.min_distance);
sound.setVolume(properties.volume * 100.0f);
sound.play();
}
示例5: playStream
void rawGenerator::playStream()
{
if (sw == 0){
if (!Buffer.loadFromSamples(waveOut, SAMPLES, 1, 44100)) {
std::cerr << "Loading failed!" << std::endl;
//return 1;
}
std::cout << "Sound 1" << std::endl;
sw = 0;
}
Sound.setBuffer(Buffer);
//Sound.setLoop(true);
Sound.play();
}
示例6: set_buzzer_tone
void ToneAlarm_SF::set_buzzer_tone(float frequency, float volume, float duration_ms)
{
if (frequency <= 0) {
return;
}
Synth::sTone tone;
tone.waveType = Synth::OSC_SQUARE;
tone.dStartFrequency = frequency;
tone.dEndFrequency = frequency;
tone.dAmplitude = 1;
envelope.dSustainTime = duration_ms/1000.0f;
Synth::generate(&soundBuffer, envelope, tone, 20000, 44100);
demoSound.setBuffer(soundBuffer);
demoSound.play();
}
示例7: handleMouseKeypress
void handleMouseKeypress(int key, int state, int x, int y)
{
switch (key) {
case GLUT_LEFT_BUTTON:
if (state == 0 && pause==FALSE){
if (gun0.bullet_number > 0) {
gun0.bullet_number--;
pistola.pushAnimation(animation(locRot(0,0,0,10,0,-10),100,std::chrono::system_clock::now()));
pistola.pushAnimation(animation(locRot(0,0,0,-10,0,10),100,std::chrono::system_clock::now()+std::chrono::milliseconds(100)));
collisionCurse();
}
else
{
sound.setBuffer(sound_youreempty);
sound.play();
}
}
break;
}
}
示例8: while
int screen_1::Run(sf::RenderWindow &App)
{
hop.setBuffer(hopFile);
trucked.setBuffer(truckedFile);
dunked.setBuffer(dunkedFile);
// Clock
sf:: Clock clock;
sf::Time time;
sf::Time delay;
// Plays Intro
intro.play();
delay = intro.getDuration();
time = clock.getElapsedTime();
// Music
while ( clock.getElapsedTime() <= delay )
{
//cout << "NO";
}
froggerTheme.setVolume(50);
froggerTheme.play();
clock.restart();
sf::Event Event;
bool Running = true;
int sum = 0;// for log testing purposes
int sum2 = 0;
int sum3 = 0;
int sum4 = 0;
int sum5 = 0;
int sum6 = 0;
int sum7 = 0;
int sum8 = 0;
int sum9 = 0;
int sum10 = 0;
while (Running)
{
// Timer Rect and Clock
double time = clock.getElapsedTime().asSeconds();
if(time >= 1.5)
{
timeRect.width = timeRect.width - 2.383;
timer.setTextureRect(timeRect);
clock.restart();
}
if(timeRect.width <= 0)
{
frogOnLily1 = false;
frogOnLily2 = false;
frogOnLily3 = false;
frogOnLily4 = false;
frogOnLily5 = false;
mainPlayer.setNumLives(3);
rectSource.width = 115;
life.setTextureRect(rectSource);
occupied1.setPosition(-100, -100);
occupied2.setPosition(-100, -100);
occupied3.setPosition(-100, -100);
occupied4.setPosition(-100, -100);
occupied5.setPosition(-100, -100);
froggerTheme.pause();
clock.restart();
timeRect.width = 143;
timer.setTextureRect(timeRect);
frogger.setPosition(320, 605);
return 2;
}
// *********************************************************************
// Creating the objects of Object class for continuous movement
//
// Object(double posX, double posY, double speed)
// *********************************************************************
// Trucks
Object t1(130, 420,0.2 );
Object t2(550, 290, 0.2);
// Cars
Object c1(-50, 420, 0.3);
Object c2(280, 289, 0.2);
Object c3(0, 289, 0.2);
// Short Logs
Object sl1(0, 125, 0.2);
Object sl2(200, 61, 0.3);
Object sl3(300, 8, 0.4);
// Long Logs
Object l1(799, 8.3, 0.4);
Object l2(500, 125, 0.2);
// Sets object's direction
t1.moveRight(truck);
t2.moveLeft(truck2);
c1.moveRight(car);
c2.moveLeft(car2);
c3.moveLeft(car3);
//.........这里部分代码省略.........
示例9: collisionCurse
void collisionCurse (void)
{
int hitten, id;
float fittX, fittY;
fittX = lastx;
fittY = windowHeight-lasty;
GLuint buff[64] = {0};
GLint hits, view[4];
//This choose the buffer where store the values for the selection data
glSelectBuffer(64, buff);
//This retrieve info about the viewport
glGetIntegerv(GL_VIEWPORT, view);
//Switching in selecton mode
glRenderMode(GL_SELECT);
//Clearing the name's stack
//This stack contains all the info about the objects
glInitNames();
//Now fill the stack with one element (or glLoadName will generate an error)
glPushName(0);
//Now modify the vieving volume, restricting selection area around the cursor
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//restrict the draw to an area around the cursor
gluPickMatrix(fittX, fittY, 5.0, 5.0, view);
gluPerspective(45.0, //The camera angle
(double)windowWidth / (double)windowHeight, //The width-to-height ratio
0.1, //The near z clipping coordinate
200.0); //The far z clipping coordinate
glutSwapBuffers();
display();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
//get number of objects drawed in that area
//and return to render mode
hits = glRenderMode(GL_RENDER);
id = target_hit(hits, buff);
if (id != -1 ){
hitten = id - 100;
if(livelli.posizione[hitten].movimento==1){
m[hitten].stato=0;
m[hitten].count=2;
m[hitten].temp_rel=t.tempoi-1;
}else if(livelli.posizione[hitten].movimento==2){
m[hitten].stato=2;
}
score += ch_index.character[ch].punteggio;
//play hit sound
if (ch_index.character[ch].punteggio>0) sound.setBuffer(sound_hit);
else sound.setBuffer(sound_ohno);
sound.play();
levelChanger();
} else {
//play miss sound
sound.setBuffer(sound_miss);
sound.play();
}
glMatrixMode(GL_MODELVIEW);
return;
}
示例10: main
// Program entry point
int main(int argc, char ** argv) {
titleImg.loadFromFile("assets/title.png");
sf::SoundBuffer sb;
sb.loadFromFile("assets/avalanche.ogg");
boulderSound.setBuffer(sb);
boulderSound.setLoop(true);
boulderSound.play();
sf::SoundBuffer sb2;
sb2.loadFromFile("assets/death.ogg");
fallingSound.setBuffer(sb2);
fallingSound.setRelativeToListener(true);
sf::SoundBuffer sb3;
sb3.loadFromFile("assets/jump.wav");
jumpingSound.setBuffer(sb3);
jumpingSound.setRelativeToListener(true);
sf::SoundBuffer sb4;
sb4.loadFromFile("assets/POL-flash-run-short.wav");
musicSound.setBuffer(sb4);
musicSound.setRelativeToListener(true);
musicSound.setVolume(15.f);
musicSound.setLoop(true);
musicSound.play();
sf::SoundBuffer sb5;
sb5.loadFromFile("assets/footsteps.ogg");
feetSound.setRelativeToListener(true);
feetSound.setBuffer(sb5);
feetSound.setLoop(true);
feetSound.setVolume(50);
feetSound.play();
sf::SoundBuffer sb6;
sb6.loadFromFile("assets/bump.ogg");
bumpSound.setRelativeToListener(true);
bumpSound.setBuffer(sb6);
bumpSound.setVolume(40);
sf::SoundBuffer sb7;
sb7.loadFromFile("assets/gem.ogg");
gemSound.setRelativeToListener(true);
gemSound.setBuffer(sb7);
gemSound.setVolume(60);
sf::SoundBuffer sb8;
sb8.loadFromFile("assets/Powerup3.wav");
powerSound.setRelativeToListener(true);
powerSound.setBuffer(sb8);
powerSound.setVolume(80);
sf::SoundBuffer sb9;
sb9.loadFromFile("assets/alert.ogg");
alertSound.setRelativeToListener(true);
alertSound.setBuffer(sb9);
//powerSound.setVolume(80);
// Create the SFML window
window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "A Bolder Escape");
while (window.isOpen()) {
events();
if (!menu) logic();
render();
}
return 0;
}