How do I play sound when a key is pressed

조회 수: 16(최근 30일)
Michael Mauricio
Michael Mauricio 2016년 12월 6일
댓글: Michael Mauricio 2016년 12월 7일
I am creating a game in matlab, how do I modify my code to play a sound when ever my character shoots (shoot key is pressed).
This is what I have so far, a working gun.
%shoot bullet
if(gamepad.isPressed(2)&& trigger_state == 0)
bullet_speed = 2500;
if(gamepad.isPressed(2)== 0)
moveXby(bullet, bullet_speed*frame_rate)
if (bullet_speed ==0)

채택된 답변

Kirby Fears
Kirby Fears 2016년 12월 6일
편집: Kirby Fears 2016년 12월 6일
This article describes how to record and play sound.
If you have a specific sound file that you need to play, try searching for that file type on this forum. However, I imagine it will be lots of fun recording your own sound effect as described in the link above.
Hope this helps.
  댓글 수: 1
Michael Mauricio
Michael Mauricio 2016년 12월 7일
Thank you for the help!

댓글을 달려면 로그인하십시오.

추가 답변(0개)


Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by