-
Notifications
You must be signed in to change notification settings - Fork 0
/
Media.cpp
58 lines (40 loc) · 1.01 KB
/
Media.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <SDL_image.h>
#include <utility>
#include <tuple>
#include <SDL_mixer.h>
#include "main.h"
#include "init.h"
//Current displayed PNG image
SDL_Texture* gPNGSurface;
// 加载背景
bool loadBackground()
{
//Loading success flag
bool success = true;
gPNGSurface = loadSurface( "res/image/loaded.png" );
if (renderer == NULL){
std::cout << SDL_GetError() << std::endl;
}
// loadSurface方法加载图像,加载失败就返回空。
if( gPNGSurface == NULL )
{
std::cout << "Failed to load PNG image!\n" << SDL_GetError() << std::endl;
success = false;
}
return success;// 返回成功
}
// 播放音乐
// 后面改成自动读取文件夹内音乐的
void PlayMusic()
{
Mix_Music *music = Mix_LoadMUS("res/music/ww.ogg");
// 加载音乐文件失败
if (!music) {
std::cout << "音频加载失败" << Mix_GetError() << std::endl;
}
else{
std::cout << "ww.ogg 读取成功" << std::endl;
}
Mix_PlayMusic(music, -1);
}