Remember me
You are here: HomeForumCyberix3D ForumGeneral DiscussionCode Block "Impulse"
Welcome, Guest
Username: Password: Remember me

TOPIC: sounds

sounds 2 weeks 2 days ago #3374

  • whinter
  • whinter's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 2
how can I make it so that when i press a key on the keyboard the sounds plays,and when i realese it stops
The administrator has disabled public write access.

sounds 2 weeks 1 day ago #3376

  • cyberix3d
  • cyberix3d's Avatar
  • OFFLINE
  • Administrator
  • Posts: 706
  • Thank you received: 699
Hello whinter,

You can achieve this functionality where a sound plays when you press a key on the keyboard and stops when you release it using the logic demonstrated in the provided image. Additionally, here’s an example you can view and test:
www.gamemaker3d.com/player?pid=01665538

key_press_sound_example.png


Explanation:
1. Loop Execution:
The logic continuously checks for key presses and changes the state of the variable play_music.

2. Key Press Handling:
• When a key (e.g., 1) is pressed, the program checks the value of the variable play_music.
• If play_music is 0 (indicating the sound is not currently playing), the following occurs:
• The sound (sound1) plays.
• A message is optionally displayed (for testing or debugging purposes).
• The variable play_music is set to 1 to indicate that the sound is now playing.

3. Key Release Handling:
• When the key is released, the program toggles back:
• The sound (sound1) stops by setting its volume to 0.
• The variable play_music is reset to 0.

This setup ensures the sound toggles on and off based on the key press/release state.

You can test this in action with the example provided in the link above. Let us know if you need further assistance!

Regards,
Cyberix3D team
The administrator has disabled public write access.
The following user(s) said Thank You: whinter
Time to create page: 0.122 seconds