hollywooFlixel actor animations by wryly

This commit is contained in:
2021-12-31 17:18:48 -07:00
parent cf87c73364
commit f2442ad618
3 changed files with 24 additions and 3 deletions

View File

@@ -2,11 +2,11 @@ package hollywoo_flixel;
import kiss.Prelude; import kiss.Prelude;
import kiss.List; import kiss.List;
import kiss.FuzzyMap;
import flixel.FlxSprite; import flixel.FlxSprite;
import hollywoo_flixel.FlxMovie; import hollywoo_flixel.FlxMovie;
typedef AnimationArgs = { typedef AnimationArgs = {
name:String,
frames:Array<Int>, frames:Array<Int>,
?frameRate:Float, // default 30 ?frameRate:Float, // default 30
?looped:Bool, // default true ?looped:Bool, // default true

View File

@@ -1,6 +1,8 @@
(prop :FlxStageFacing defaultFacing) (prop :FlxStageFacing defaultFacing)
(defNew [:String assetPath &opt frameWidth frameHeight :FlxStageFacing defaultFacing :Map<String,AnimationArgs> animations] (prop :FuzzyMap<String> animationNames (new FuzzyMap<String>))
(defNew [&prop :String assetPath &opt frameWidth frameHeight :FlxStageFacing defaultFacing :Map<String,AnimationArgs> animations]
(super) (super)
(set this.defaultFacing (or defaultFacing Right)) (set this.defaultFacing (or defaultFacing Right))
@@ -10,6 +12,7 @@
(loadGraphic assetPath)) (loadGraphic assetPath))
(when animations (when animations
(doFor =>name animationArgs animations (doFor =>name animationArgs animations
(dictSet animationNames name name)
(animation.add (animation.add
name name
animationArgs.frames animationArgs.frames
@@ -17,3 +20,12 @@
(or animationArgs.looped true) (or animationArgs.looped true)
?animationArgs.flipX ?animationArgs.flipX
?animationArgs.flipY)))) ?animationArgs.flipY))))
(method :Void playAnimation [fuzzySearchKey]
(if (animationNames.exists fuzzySearchKey)
(animation.play (dictGet animationNames fuzzySearchKey) true)
(#when debug
(print "WARNING! No animation matches $fuzzySearchKey for actor with spritesheet $assetPath"))))
(method :Void stopAnimation []
(animation.stop))

View File

@@ -104,6 +104,15 @@
(method showDialog [:String speakerName :SpeechType<FlxStagePosition,FlxStageFacing,ActorFlxSprite> type :String wryly :String text :Continuation cc] (method showDialog [:String speakerName :SpeechType<FlxStagePosition,FlxStageFacing,ActorFlxSprite> type :String wryly :String text :Continuation cc]
// TODO handle text messages, wrylies, off-screen, from-phone, etc. via (case type) // TODO handle text messages, wrylies, off-screen, from-phone, etc. via (case type)
// TODO attribute on-screen dialogue to the character's stageposition // TODO attribute on-screen dialogue to the character's stageposition
// When the actor is in the scene, check for an animation matching the wryly
(doFor =>actorName character currentState.characters
(when (= actorName speakerName)
(let [actor (the ActorFlxSprite character.actor)]
(if wryly
(actor.playAnimation wryly)
(actor.playAnimation "neutral")))))
// Make a dialog box // Make a dialog box
(unless dialogBox (unless dialogBox
(set dialogBox (new FlxSprite DIALOG_X DIALOG_Y)) (set dialogBox (new FlxSprite DIALOG_X DIALOG_Y))