From 39034ad3f42109e7e8b3c7bfa8f2ec2efda4aeba Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 18 Apr 2023 15:02:04 -0600 Subject: [PATCH] linearMotion handle looped sound --- .../src/hollywoo_flixel/FlxDirector.kiss | 3 +++ .../src/hollywoo_flixel/FlxMovie.hx | 2 +- .../hollywoo_flixel/HollywooFlixelDSL.kiss | 22 ++++++++++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss index ef7ff4b4..68f9e297 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxDirector.kiss @@ -364,6 +364,9 @@ (unless waitForEnd (cc))) (method :Void stopSound [:FlxSound sound] + (when (flxMovie.loopingOnCompletes.exists sound) + ((dictGet flxMovie.loopingOnCompletes sound)) + (flxMovie.loopingOnCompletes.remove sound)) (currentSounds.remove sound) (sound.stop)) diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxMovie.hx b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxMovie.hx index 5b7b3c9b..1e09c4ed 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/FlxMovie.hx +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/FlxMovie.hx @@ -31,7 +31,7 @@ class FlxMovie extends Movie = []; - + public var loopingOnCompletes:MapVoid> = []; public var STAGE_LEFT_X:Float; public var STAGE_RIGHT_X:Float; public var ACTOR_WIDTH:Int; diff --git a/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss b/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss index febbdaff..54f96b60 100644 --- a/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss +++ b/projects/hollywoo-flixel/src/hollywoo_flixel/HollywooFlixelDSL.kiss @@ -18,14 +18,22 @@ (when cc (cc)) })) -(method linearMotion [:FlxSprite sprite :Float destX :Float destY :Float speed &opt :Void->Void cc] +(method linearMotion [:FlxSprite sprite :Float destX :Float destY :Float speed &opt :Void->Void cc :String soundLoop :Float volumeMod] + (when soundLoop + (let [oldCC cc] + (set cc + (makeCC + (stopSound soundLoop (makeCC null)) + (when oldCC + (oldCC))))) + (loopSound soundLoop (makeCC null) volumeMod)) (tween (FlxTween.linearMotion sprite sprite.x sprite.y destX destY speed false (tweenOpts cc)))) (defAlias &ident FlxTween.linearMotion CHANGE_TO_MOVIE_LINEARMOTION) -(method linearMotionTo [:FlxSprite sprite :String positionKey :Float speed &opt :Void->Void cc] +(method linearMotionTo [:FlxSprite sprite :String positionKey :Float speed &opt :Void->Void cc :String soundLoop :Float volumeMod] (let [position (resolvePosition positionKey)] - (linearMotion sprite position.x position.y speed cc))) + (linearMotion sprite position.x position.y speed cc soundLoop volumeMod))) (method newFlxSet [name assetPath] (let [setSprite (new FlxSprite 0 0)] @@ -86,8 +94,12 @@ (method loopSound [name :Void->Void cc &opt :Float volumeMod] (playSound name (makeCC null) volumeMod false) - (let [cs flxDirector.currentSounds] - (set .looped (nth cs (- cs.length 1)) true)) + (let [cs flxDirector.currentSounds + sound (nth cs (- cs.length 1)) + onComplete sound.onComplete] + (dictSet loopingOnCompletes sound onComplete) + (set sound.onComplete null) + (set sound.looped true)) (cc)) (preload