-
Notifications
You must be signed in to change notification settings - Fork 5
Add Sound#loop_count=. #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おぉ、これはいいですね!
dxruby_sdlはわりとゴールがわかりやすいので、高専生が修正するのもできそうですね。
lib/dxruby_sdl/sound.rb
Outdated
|
||
def initialize(filename) | ||
@music = SDL::Mixer::Music.load(filename) | ||
@loop_count = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
インスタンス変数の名前ですが、dxrubyだとインスタンス変数を定義しないと思うので、@_loop_countとして、先頭にアンダーバーをつけてもらえますかね。
Spriteの@xが衝突して困ったことになっているのですよね^_^;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@_loop_count
に名前を変更するのを 91ea522 で修正しました。
@loop_countを@_loop_countに修正してもらえたらマージします! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ごめんよ、もう少し修正してほしいところがあったよ 🙇
spec/lib/dxruby_sdl/sound_spec.rb
Outdated
describe '#loop_count=' do | ||
context 'WAVE file', wave: true do | ||
it 'SDL::Waveのループ回数を変更する' do | ||
expect(sound.instance_variable_get('@sound') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ごめんよ、もう1点、修正してほしいところがありました。
ここでのチェックですが、インスタンス変数の値をチェックするのではなくて、
https://github.com/sada/dxruby_sdl/blob/91ea522c83edf17b9ad0270783872e9d13eb7182/spec/lib/dxruby_sdl/sound_spec.rb#L44
や
https://github.com/sada/dxruby_sdl/blob/91ea522c83edf17b9ad0270783872e9d13eb7182/spec/lib/dxruby_sdl/sound_spec.rb#L78
のように、 SDL::Mixer#play_channel
の第3引数が #loop_count=
で指定した 1 になっているかどうかをチェックしてもらえますでしょうか?
出来る限り、 @_loop_count
は外に出したくないからです。
以下のような感じを想定しています。
wave = sound.instance_variable_get('@sound').instance_variable_get('@wave')
expect(SDL::Mixer).to receive(:play_channel).with(-1, wave, 1)
sound.loop_count = 1
sound.play
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テストを SDL::Mixer#play_channel
が呼び出された時の引数を確認するように 01b510b で修正しました。
spec/lib/dxruby_sdl/sound_spec.rb
Outdated
|
||
context 'MIDI file', midi: true do | ||
it 'SDL::Musicのループ回数を変更する' do | ||
expect(sound.instance_variable_get('@sound') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここも同じで、以下のような感じに修正してもらえるかな。
music = sound.instance_variable_get('@sound').instance_variable_get('@music')
expect(SDL::Mixer).to receive(:play_music).with(music, 1)
sound.loop_count = 1
sound.play
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テストを SDL::Mixer#play_music
が呼び出された時の引数を確認するように 01b510b で修正しました。
ありがとうございました! |
スモウルビーの「終わるまで( )の音を鳴らす」に当たる
play_until_done
を作成するために、音の何回鳴らすか(ループ回数)を変更できるSound#loop_count=
を追加しました。DXRubyのドキュメントの http://mirichi.github.io/dxruby-doc/api/Sound_23loop_count_3D.html を参考にして
Sound#loop_count=
の引数をn
にしました。あと http://dxruby.osdn.jp/DXRubyReference/20095318417765.htm に
Sound#loopCount=
の記述があったので別名で呼び出せるようにしました。dxruby_sdlのサンプルを使用して、以下のプログラムでループ回数を変更できることを確認しました。