little help?
A sprite shakes if a certain condition is met and function called. I'd like to play a sound effect while it shakes. But I cant seem to make it play the whole sound effect because it starts over with each update and buzzes rather than plays. I can get the sound effect, or I can get the animation, but cant seem to make them both happen at the same time.
I've tried many different variations and schemes, but here is one example:
function _init() correct = nil tics = 30 end function _update() if (correct == false) shake() end function _draw() draw_stuff() end function shake() sfx(0) tics -= 1 if tics > 0 then mysprite.x = mysprite.x + cos(t()/.1) --makes it shake back and forth else correct = nil tics = 30 end end |
I can see why it doesn't work; because it is calling the sfx(0)
again and starting over every time shake()
is called. But what is the right way of thinking about playing the sound along with an animation? I read about coroutines, but am not sure if that is actually needed for something this basic. I'd also like to just be able to call the function whenever I want and not bother checking in _update()
every frame.
I'll be grateful for any good example, tips, explanation or pointing in the right direction. Thank you.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](https://www.lexaloffle.com/bbs/files/32759/comovic.gif)
Set the loop value on the sfx screen. For example, you can repeat notes 0-7 on the sfx0 track, or play 0-15 and loop 8-15 repeatedly. The latter is used like the charge sound of Mega Man.
![](/media/32759/3_0.gif)
It detects the tick value, plays the sfx, and stops the sfx at the end.
[Please log in to post a comment]