ios - Spritekit Multi-Node animation sequencer, can this be made more performant? -


i needed able sequence set of skactions operating on multiple nodes , wrote test. it's easy sequence multiple actions on single node there no direct support run sequences 1 after operating on multiple nodes (such swap 2 nodes location flash other nodes fade in more nodes). following code handles sequencing, wonder if scanning nodes each update might take time if number of nodes big.

class animatorsequence {     var animatorstack = [animator]()     var currentanimator : animator!      func startanimator()     {         currentanimator = animatorstack.removeatindex(0)         currentanimator.execute()     }      func addanimator( animator : animator )     {         animatorstack.append(animator)         if currentanimator==nil && animatorstack.count == 1         {             startanimator();         }     }      func process()     {         if let anim = currentanimator         {             if anim.isdone()             {                 currentanimator = nil                 if animatorstack.count > 0                 {                     startanimator();                 }             }         }     } }  let animatorsequencer = animatorsequence()  class animator {     typealias functiontype = (() -> void)?     var function : functiontype     var parentnode : sknode      init (function:functiontype, parent : sknode)     {         self.function = function         self.parentnode = parent     }      func execute()     {         if let f = function         {             f()         }     }      func isdone() -> bool     {         var count = parentnode.children.count         node in parentnode.children         {             if !node.hasactions()             {                 count--;             }         }         return count==0;     } } 

example call:

    let = animator(function: { () -> void in          firstdot.node.runaction(movetosecond)         seconddot.node.runaction(movetofirst)          }         , parent : self     )      animatorsequencer.addanimator(a) 

and each update

override func update(currenttime: cftimeinterval) {     animatorsequencer.process() } 

the point of allow me sequence number of multiple-node animations nothing more closure , not require complicated. seems work wonder if there more performant way determine if skactions complete.

i wrote class looking for. queue of skactions called 1 after another. add queue processed sequentially no longer have worry call routines. can add actions multiple different skspritenodes without having create action sequences.

https://github.com/evannnc/actionq


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -