-
Notifications
You must be signed in to change notification settings - Fork 435
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
Add pitch support for FlxSound #1465
Changes from 4 commits
54925d1
4d3e446
ab0ae41
0d80ef5
6ef5046
6fdaba4
b41c326
9d26681
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,10 @@ class FlxSound extends FlxBasic | |
* Set volume to a value between 0 and 1 to change how this sound is. | ||
*/ | ||
public var volume(get, set):Float; | ||
/** | ||
* Set pitch, which also alters the playback speed. Normal is 1. | ||
*/ | ||
public var pitch(get, set):Float; | ||
/** | ||
* The position in runtime of the music playback. | ||
*/ | ||
|
@@ -107,6 +111,10 @@ class FlxSound extends FlxBasic | |
* Internal tracker for volume. | ||
*/ | ||
private var _volume:Float; | ||
/** | ||
* Internal tracker for pitch. | ||
*/ | ||
private var _pitch:Float = 1.0; | ||
/** | ||
* Internal tracker for total volume adjustment. | ||
*/ | ||
|
@@ -518,6 +526,9 @@ class FlxSound extends FlxBasic | |
_channel = _sound.play(time, numLoops, _transform); | ||
if (_channel != null) | ||
{ | ||
#if (cpp || neko) | ||
pitch = _pitch; | ||
#end | ||
_channel.addEventListener(Event.SOUND_COMPLETE, stopped); | ||
active = true; | ||
} | ||
|
@@ -629,6 +640,23 @@ class FlxSound extends FlxBasic | |
return Volume; | ||
} | ||
|
||
|
||
private inline function get_pitch():Float | ||
{ | ||
return _pitch; | ||
} | ||
|
||
private function set_pitch(v:Float):Float | ||
{ | ||
#if (cpp || neko) | ||
_channel.pitch = v; | ||
#else | ||
FlxG.log.warn("Pitch is only supported on OpenAL targets (i.e. cpp & neko)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if it wouldn't be better to only have this property exist for cpp and neko in the first place. That's how we handle most of the input stuff in |
||
#end | ||
return _pitch = v; | ||
} | ||
|
||
|
||
private inline function get_pan():Float | ||
{ | ||
return _transform.pan; | ||
|
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.
"Default" would probably describe this better than "Normal".