.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

การใส่เสียง music ให้กับ game Options · View
paedotnet
Posted: Friday, October 03, 2008 10:25:20 PM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 345
Location: bkk

การใส่จังหวะดนตรีให้กับเกมส์

ในการสร้าง Background Music นี้มีวิธีสร้างเหมือนกับ การสร้าง sound bank ,wave bank
ดูที่ http://www.codetoday.net/yaf_postst1301_-xna.aspx โดยให้เพิ่มเสียง ดนตรีเข้าไป

แล้วเขียนโค้ดดังนี้


Cue playmusic;


ในเมธอด LoadContent ก็เขียนโค้ดดังนี้

 playmusic = sound_game.GetCue("SoundLoop (10)"); // SoundLoop (10) เป็นชื่อไฟล์เสียง

จากนั้นในเมธอด update ก็เขียนโค้ดเพื่อสั่งให้เล่นไฟล์เสียงนี้

  KeyboardState ks = Keyboard.GetState();
           if (ks.IsKeyDown(Keys.P)) //เมื่อคลิกที่ปุ่ม p ก็ให้เล่นเสียง
            {
                playmusic.Play();
            }


 



[With great power comes great responsibility]
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by