怎么在C++中给一个游戏添加背景音乐代码

张珞娅 2015-01-02 08:49:27
求助各路大神,如何添加背景音乐代码?可以的话我可以提供扫雷的源代码,各位来挑战吧?
...全文
1186 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
张珞娅 2015-01-04
  • 打赏
  • 举报
回复
不好意思,谢谢你。实在是学不会编程,下周就要交作业了,弄了好久也没懂,麻烦你们了,对不起。
lucifer886 2015-01-04
  • 打赏
  • 举报
回复
引用 6 楼 nizhenshidashen 的回复:
不太懂什么意思耶,您能写个代码示范一下吗?
说句不好听的话,自己多想想,想到哪问到哪谁帮的了你?前面已经有朋友回答你了,如果你还是不知道就去把基础知识学扎实点吧,看看文档,用什么基本的东西都不知道谁帮你?
Evankaka 版主 2015-01-04
  • 打赏
  • 举报
回复
是的,你只想要加音乐的话,都不用改它原来的代码了,就在它的基础上加函数
张珞娅 2015-01-04
  • 打赏
  • 举报
回复
看不懂。。。。。那个Password后进入主程序的怎么破?
赵4老师 2015-01-04
  • 打赏
  • 举报
回复
PlaySound The PlaySound function plays a sound specified by the given filename, resource, or system event. (A system event may be associated with a sound in the registry or in the WIN.INI file.) BOOL PlaySound( LPCSTR pszSound, HMODULE hmod, DWORD fdwSound ); Parameters pszSound A string that specifies the sound to play. If this parameter is NULL, any currently playing waveform sound is stopped. To stop a non-waveform sound, specify SND_PURGE in the fdwSound parameter. Three flags in fdwSound (SND_ALIAS, SND_FILENAME, and SND_RESOURCE) determine whether the name is interpreted as an alias for a system event, a filename, or a resource identifier. If none of these flags are specified, PlaySound searches the registry or the WIN.INI file for an association with the specified sound name. If an association is found, the sound event is played. If no association is found in the registry, the name is interpreted as a filename. hmod Handle of the executable file that contains the resource to be loaded. This parameter must be NULL unless SND_RESOURCE is specified in fdwSound. fdwSound Flags for playing the sound. The following values are defined: SND_APPLICATION The sound is played using an application-specific association. SND_ALIAS The pszSound parameter is a system-event alias in the registry or the WIN.INI file. Do not use with either SND_FILENAME or SND_RESOURCE. SND_ALIAS_ID The pszSound parameter is a predefined sound identifier. SND_ASYNC The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL. SND_FILENAME The pszSound parameter is a filename. SND_LOOP The sound plays repeatedly until PlaySound is called again with the pszSound parameter set to NULL. You must also specify the SND_ASYNC flag to indicate an asynchronous sound event. SND_MEMORY A sound event's file is loaded in RAM. The parameter specified by pszSound must point to an image of a sound in memory. SND_NODEFAULT No default sound event is used. If the sound cannot be found, PlaySound returns silently without playing the default sound. SND_NOSTOP The specified sound event will yield to another sound event that is already playing. If a sound cannot be played because the resource needed to generate that sound is busy playing another sound, the function immediately returns FALSE without playing the requested sound. If this flag is not specified, PlaySound attempts to stop the currently playing sound so that the device can be used to play the new sound. SND_NOWAIT If the driver is busy, return immediately without playing the sound. SND_PURGE Sounds are to be stopped for the calling task. If pszSound is not NULL, all instances of the specified sound are stopped. If pszSound is NULL, all sounds that are playing on behalf of the calling task are stopped. You must also specify the instance handle to stop SND_RESOURCE events. SND_RESOURCE The pszSound parameter is a resource identifier; hmod must identify the instance that contains the resource. SND_SYNC Synchronous playback of a sound event. PlaySound returns after the sound event completes. Return Values Returns TRUE if successful or FALSE otherwise. Remarks The sound specified by pszSound must fit into available physical memory and be playable by an installed waveform-audio device driver. PlaySound searches the following directories for sound files: the current directory; the Windows directory; the Windows system directory; directories listed in the PATH environment variable; and the list of directories mapped in a network. For more information about the directory search order, see the documentation for the OpenFile function. If it cannot find the specified sound, PlaySound uses the default system event sound entry instead. If the function can find neither the system default entry nor the default sound, it makes no sound and returns FALSE. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in mmsystem.h. Import Library: Use winmm.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also Waveform Audio Overview, Waveform Functions
张珞娅 2015-01-04
  • 打赏
  • 举报
回复
不太懂什么意思耶,您能写个代码示范一下吗?
勤奋的小游侠 2015-01-04
  • 打赏
  • 举报
回复
先将主界面隐藏,显示登陆界面。登陆界面登陆后,显示主界面,隐藏登陆界面
张珞娅 2015-01-04
  • 打赏
  • 举报
回复
好的。我弄了个登陆界面,要怎样实现登陆成功后直接进入主程序界面呢? 类是CPasswordDlg ,用户名是船电,密码是123456,主程序类是Mine,能帮我具体写一下如何让实现登陆成功后自动进入主程序吗?
张珞娅 2015-01-03
  • 打赏
  • 举报
回复
是的,刚接触,不太懂这些。我有了源代码,要弄线程进去直接加代码进去就行了吗,不用弄别的吗
Evankaka 版主 2015-01-02
  • 打赏
  • 举报
回复
添加背景音乐代码?你是想游戏中一直放音乐么?直接开个线程播放音乐就是了,然后弄成死循环。加个判断条件退出
浅墨出品,零资源分下载,分享精神至上~ 5.0版新加入多3D模型载入功能类,载入了地狱恶魔,人类骑士,天堂雷龙三个精美的游戏模型。 另外,关于雪花粒子效果提醒大家一下,可在SnowParticleClass.h的PARTICLE_NUMBER宏改变雪花粒子数量,默认粒子数量为3000,1G显存的显卡取10万粒子数量帧数就只有8帧了。所以要自己改雪花粒子数量的话请根据自己的显卡性能酌情选择,如果你取个非常大的50万粒子数量,显卡吃不消烧了可别怪我- - 其的3D人物模型来自英雄无敌6。 背景音乐来自魔兽争霸3。 一个综合型的Direct3D示例程序的5.0版。 用键盘上W,A,S,D,I,J,K,L,↑,↓,←,→12个键加上鼠标在美丽的三维空间翱翔。包括了Direct3D初始化,DirectInput输入处理,顶点缓存,光照与材质,文字输出,颜色,纹理贴图,四大变换,网格模型,X文件载入等等知识(当然还有默认被开启的深度缓存),以及地形系统模拟,三维天空模拟,粒子系统。 源码的配套博文是 《 【Visual C++游戏开发五十一 浅墨DirectX教程十九 网格模型进阶之路》 ,文章地址为http://blog.csdn.net/zhmxy555/article/details/8770426, 点击Release文件夹下的exe文件可以直接看到运行效果,运行需要DirectX运行库的支持。报缺少D3D的DLL系列错误的童鞋们请google/百度一下 “DirectX 9.0c runtime”,下载并装个最新版的。 报缺少MVCR100D.Dll错误的朋友们去下一个安装就可以了,或者直接点击sln打开工程再次编译一次。 如果是想调试并运行源代码,但是报错了,请去下载最新版DirectX SDK并进行DirectX开发环境的配置。 编写环境:VS2010 我的博客地址是http://blog.csdn.net/zhmxy555,源码结合配套文章一起看效果更佳。 希望能和大家一起交流,共同学习,共同进步。

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧