本文整理汇总了C++中Music::setVolume方法的典型用法代码示例。如果您正苦于以下问题:C++ Music::setVolume方法的具体用法?C++ Music::setVolume怎么用?C++ Music::setVolume使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Music
的用法示例。
在下文中一共展示了Music::setVolume方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: playMainMenu
void MasterClass::playMainMenu()
{
if(game != NULL)
{
delete game;
game = NULL;
}
window->setView(window->getDefaultView());
Clock clock;
Vector2u window_size = window->getSize();
// Chargement de l'image du menu principal
sf::Texture texture;
texture.loadFromFile("res/tex/decor/menu_metal_slug2.png");
Vector2u texture_size = texture.getSize();
sf::Sprite sprite(texture);
sprite.scale((float)window_size.x/texture_size.x, (float)window_size.y/texture_size.y);
// Création d'un EnemiView pour une petite animation
Int2 rebel_siren_position((int)window_size.x*0.875, (int)window_size.y*0.722);
EnemyView rebel_siren(rebel_siren_position, Enemy::REBEL, false);
rebel_siren.changeAnimation(EnemyView::REBEL_SIREN);
// Création du menu principal
Font font;
font.loadFromFile("res/font/arcade.ttf");
vector<String> vectItems;
vectItems.push_back("Nouvelle partie");
const int newGame = 0;
vectItems.push_back("Reglages");
const int settings = 1;
vectItems.push_back("Quitter");
const int exit = 2;
Menu menu(vectItems, window, font, Menu::TOPRIGHTHANDCORNER, (unsigned int)window_size.y*0.0444);
// Chargement et lecture de la musique du menu principal
Music music;
music.openFromFile("res/snd/level/Main_Theme_From_Metal_Slug.wav");
music.setVolume(config.musicsVolume);
music.setLoop(true);
music.play();
while (window->isOpen() && state == MAINMENU)
{
sf::Event event;
while (window->pollEvent(event))
{
if (event.type == Event::KeyPressed)
{
switch(event.key.code)
{
case Keyboard::Up :
menu.moveUp();
break;
case Keyboard::Down :
menu.moveDown();
break;
case Keyboard::Return :
switch(menu.getSelectedItemIndex())
{
case newGame :
previousState = state;
state = NEWGAME;
break;
case settings :
previousState = state;
state = SETTINGS;
break;
case exit :
previousState = state;
state = EXIT;
break;
default :
break;
}
break;
default :
break;
}
}
}
int t = clock.restart().asMilliseconds();
rebel_siren.animate(t);
window->clear();
window->draw(sprite);
menu.draw(window);
rebel_siren.display(window);
window->display();
}
}
示例2: playSettings
void MasterClass::playSettings()
{
Vector2u window_size = window->getSize();
Image img = window->capture();
Texture texture;
//texture.loadFromImage(img);
texture.loadFromFile("res/tex/decor/settings_menu.png");
Vector2u texture_size = texture.getSize();
Sprite sprite(texture);
// 0 -> pas transparent et 255 -> transparent
//sprite.setColor(sf::Color(255, 255, 255, 128));
sprite.scale((float)window_size.x/texture_size.x, (float)window_size.y/texture_size.y);
View view = window->getView();
sprite.setPosition(view.getCenter().x - (float)window_size.x/2, 0);
Font font;
font.loadFromFile("res/font/arcade.ttf");
vector<String> vectItems;
vectItems.push_back("Reprendre");
const int resume = 0;
vectItems.push_back("<- Volume musique +>");
const int musicsVolume = 1;
vectItems.push_back("<- Volume bruitages +>");
const int soundEffectsVolume = 2;
vectItems.push_back("Menu principal");
const int mainMenu = 3;
Menu menu(vectItems, window, font, Menu::CENTER, (unsigned int)window_size.y*0.0444);
SoundBuffer buffer;
Sound s;
buffer.loadFromFile("res/snd/enemy/rebel/death1.wav");
s.setBuffer(buffer);
Music music;
music.openFromFile("res/snd/level/The_Military_System.wav");
music.setVolume(config.musicsVolume);
music.setLoop(true);
music.play();
while (window->isOpen() && state == SETTINGS)
{
sf::Event event;
while(window->pollEvent(event))
{
if (event.type == Event::KeyPressed)
{
switch(event.key.code)
{
case Keyboard::Escape :
state = previousState;
break;
case Keyboard::Up :
menu.moveUp();
break;
case Keyboard::Down :
menu.moveDown();
break;
case Keyboard::Return :
switch(menu.getSelectedItemIndex())
{
case resume :
state = previousState;
break;
case mainMenu :
previousState = state;
state = MAINMENU;
break;
default :
break;
}
break;
case Keyboard::Left :
switch(menu.getSelectedItemIndex())
{
case musicsVolume :
config.musicsVolume -= 10;
if(config.musicsVolume < 0)
config.musicsVolume = 0;
music.setVolume(config.musicsVolume);
break;
case soundEffectsVolume :
config.soundEffectsVolume -= 10;
if(config.soundEffectsVolume < 0)
config.soundEffectsVolume = 0;
s.setVolume(config.soundEffectsVolume);
s.play();
break;
default :
break;
}
break;
//.........这里部分代码省略.........
示例3: main
int main()
{
RenderWindow window(VideoMode(1300,702),"Find the fish", Style::Default);
window.setPosition(Vector2i(10,10));
menu(window);
int cntMeow = 0;
//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
Texture texture;
texture.loadFromFile("images/level1empty.jpg");
Sprite level(texture);
//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
Music mainSong;
mainSong.openFromFile("music/level1.ogg");
mainSong.play();
mainSong.setLoop(true);
mainSong.setVolume(75);
//>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
Player p("cat.png", 55, 25, 200, 120, 45, 445);
Clock clock;
//>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
SoundBuffer buf1, buf2;
buf1.loadFromFile("music/meow1.ogg");
buf2.loadFromFile("music/meow2.ogg");
Sound meow1, meow2;
meow1.setBuffer(buf1);
meow2.setBuffer(buf2);
//Objects
Object posters("tayles1.png", 160, 660, 210, 250, 280, 215);
Object bed("tayles1.png", 420, 80, 280, 310, 250, 440);
Object toys("tayles1.png", 120, 470, 180, 150, 220, 545);
Object upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83);
Object cabinet("tayles1.png", 75, 40, 250, 350, 605, 305);
Object mop("tayles1.png", 515, 785, 165, 241, 587, 385);
Object flower("tayles1.png", 780, 65, 170, 330, 147, 285);
Object ball("tayles1.png", 905, 615, 40, 55, 357, 190);
Object books("tayles1.png", 860, 735, 125, 80, 290, 187);
while (window.isOpen())
{
float time = clock.getElapsedTime().asMicroseconds();
clock.restart();
time = time/500;
Vector2i pos = Mouse::getPosition(window);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
//>>>>>----Meow----<<<<<<
if (event.type == Event::MouseButtonPressed)
if (event.key.code == Mouse::Left)
if (p.sprite.getGlobalBounds().contains(pos.x, pos.y))
{
if(cntMeow == 5)
{
meow2.play();
cntMeow = 0;
}
meow1.play();
cntMeow++;
}
//------------------------------------------------------------------------------
}
p.update(time);
window.clear();
window.draw(level);
window.draw(posters.sprite);
window.draw(bed.sprite);
window.draw(toys.sprite);
window.draw(upShelf.sprite);
window.draw(cabinet.sprite);
window.draw(mop.sprite);
window.draw(flower.sprite);
window.draw(ball.sprite);
window.draw(books.sprite);
window.draw(p.sprite);
window.display();
}
}
示例4: main
int main()
{
//Crear una ventana
Vector2f windowMedidas;
windowMedidas.x = 640; windowMedidas.y = 360;
RenderWindow window(VideoMode(windowMedidas.x, windowMedidas.y), "Urban Mind (Demo)");
window.setFramerateLimit(60);
//Crear la V-Cam
Vector2f CamaraPosicion, CamaraMedidas;
CamaraPosicion.x = 0; CamaraPosicion.y = 0;
CamaraMedidas.x = 640; CamaraMedidas.y = 360;
View Camara(FloatRect(CamaraPosicion.x, CamaraPosicion.y, CamaraMedidas.x, CamaraMedidas.y));
Camara.setCenter(CamaraMedidas.x / 2, CamaraMedidas.y / 2);
int Screen = 1, nivel = 1, nivelMaximoAlcanzado = nivel; // Screen 1 = Menu, 2 = Niveles, 3 Otros...
//Menu
Texture BackgroundIMG;
BackgroundIMG.loadFromFile("Dibujos/MainBackground.jpg");
Sprite BGIMG;
BGIMG.setTexture(BackgroundIMG);
BGIMG.setOrigin(BackgroundIMG.getSize().x / 2, BackgroundIMG.getSize().y / 2);
BGIMG.scale(0.48, 0.48);
BGIMG.setPosition(320, 180);
//Musica del menu
sf::Music BgMainMusic;
BgMainMusic.openFromFile("Musica/MainTheme.ogg");
BgMainMusic.setVolume(50);
BgMainMusic.setLoop(true);
//Musica del juego
Music LevelMusic;
LevelMusic.openFromFile("Musica/LevelMusic.ogg");
LevelMusic.setVolume(80);
LevelMusic.setLoop(true);
//Efecto de sonide empujar caja
SoundBuffer DragFX;
DragFX.loadFromFile("Musica/PullBox.ogg");
Sound BoxFx(DragFX);
//Botones
int Selected = 0;
bool KeyPressed = false;
Boton Jugar = Boton(Vector2f(320, 180), "Dibujos/1Off.png", "Dibujos/1ON.png", 0.5), Salir = Boton(Vector2f(320, 230), "Dibujos/2Off.png", "Dibujos/2ON.png", 0.5);
//Cosas inGame
jugador yo = jugador(0,0);
bloque box = bloque(1);
bloque Tile1 = bloque(0);
Texture TexturaMeta;
TexturaMeta.loadFromFile("Dibujos/TSprite.jpg");
Sprite Meta;
Meta.setTexture(TexturaMeta);
Meta.setOrigin(TexturaMeta.getSize().x / 2, TexturaMeta.getSize().y/2);
Meta.scale(0.1,0.1);
Vector2f coordenadasParaGanar;
//Letras
Font sansation;
sansation.loadFromFile("Retro_Computer.ttf");
Text scoreLabel("", sansation, 12);
scoreLabel.setPosition(34, 15 * 34);
scoreLabel.setColor(Color::White);
//Contenedor de posiciones (Cajas), Contenedor de posiciones (Suelo)
vector <Vector2f> contenedorDeCajas, contenedorDeSuelo;
//Gameloop
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
};
if (window.hasFocus()) //Si la aplicacion esta seleccionada
{
window.clear();
switch (Screen)
{
case 1: //Menu principal
//Si la musica no se esta reproduciendo...
if (BgMainMusic.getStatus() != 2)
BgMainMusic.play();
window.draw(BGIMG); //Dibujar fondo
window.draw(Jugar.getSprite()); //Dibujar boton de jugar
window.draw(Salir.getSprite()); //Dibujar boton de salir
//Cambiar seleccion de boton
if (!(Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down)) && (Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up)) && Selected > 0 && !KeyPressed)
{
Selected--;
KeyPressed = true;
}
else if ((Keyboard::isKeyPressed(Keyboard::S) || Keyboard::isKeyPressed(Keyboard::Down)) && !(Keyboard::isKeyPressed(Keyboard::W) || Keyboard::isKeyPressed(Keyboard::Up)) && Selected < 1 && !KeyPressed)
{
Selected++;
KeyPressed = true;
}
//.........这里部分代码省略.........
示例5: mainLevel
void mainLevel(RenderWindow &window)
{
//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
Level lvl;
lvl.LoadFromFile("map.tmx");
//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
Texture texture;
texture.loadFromFile("images/level1empty.jpg");
Sprite level(texture);
Texture texture2;
texture2.loadFromFile("images/levelShad.png");
Sprite level2(texture2);
Texture texture3;
texture3.loadFromFile("images/level12.png");
Sprite level3(texture3);
//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
Music mainSong;
Music skyrim, muse, bathMus;
bathMus.openFromFile("music/bath.ogg");
Object mus = lvl.GetObject("muse");
muse.openFromFile("music/synd.ogg"); muse.setVolume(100);
skyrim.openFromFile("music/skyrim.ogg"); skyrim.setVolume(100);
mainSong.openFromFile("music/level1.ogg");
mainSong.play();
mainSong.setLoop(true);
mainSong.setVolume(75);
//>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
Object player = lvl.GetObject("cat");
Object fish = lvl.GetObject("fish");
Object mo = lvl.GetObject("mouse");
Object ob = lvl.GetObject("catPlace");
Player cat("cat.png", lvl, 68, 429, 60, 120, player.rect.left, player.rect.top, ELSE);
Clock clock;
Clock gameTimeClock;
int sinkCnt = 0;
//>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
SoundBuffer buf1, buf2;
buf1.loadFromFile("music/meow1.ogg");
buf2.loadFromFile("music/meow2.ogg");
Sound meow1, meow2;
meow1.setBuffer(buf1);
meow2.setBuffer(buf2);
SoundBuffer buf, buf3;
buf.loadFromFile("music/steklo.ogg");
buf3.loadFromFile("music/mouse.ogg");
Sound glass; Sound mouseS;
glass.setBuffer(buf); glass.setVolume(100);
mouseS.setBuffer(buf3);
//Objects
Furniture posters("tayles1.png", 160, 660, 210, 250, 280, 215, POSTERS);
Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440, ELSE);
Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545, TOYS);
Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83, SHELF);
Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305, CABINET);
Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385, MOP);
Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285, ELSE);
Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190, BALL);
Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187, BOOKS);
Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430, ELSE);
Furniture key("tayles1.png", 1, 1, 25, 25, 430, 425, KEY);
Furniture cabinetEnd("cabinet.png", 20, 50, 270, 350, 590, 290, ELSE);
Furniture girl("girlHair.png", 1,1, 96, 45, 1075, 350, ELSE);
Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350, ELSE);
Furniture puddle("tayles1.png",789, 1000, 204, 75, 1057, 559, ELSE);
Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430, ELSE);
Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565, ELSE);
Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330, BATH);
Furniture openBath("bathr.png", 264, 79, 339, 369, 1015, 315, ELSE);
Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530, ELSE);
Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300, ELSE);
Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450, SINK);
Furniture sinkWater("bathr.png", 22, 180, 197, 427, 1200, 540, ELSE);
Furniture mou("mouse.png", 2, 21, 32, 25, mo.rect.left, mo.rect.top, ELSE);
std::list<Furniture> fList;
std::list<Furniture>::iterator it;
fList.push_back(posters);
fList.push_back(toys);
fList.push_back(upShelf);
fList.push_back(cabinet);
fList.push_back(mop);
fList.push_back(ball);
fList.push_back(books);
fList.push_back(key);
fList.push_back(puddle);
fList.push_back(brokenLight);
fList.push_back(bath);
fList.push_back(sink);
//.........这里部分代码省略.........