@@ -35,6 +35,7 @@ cc.BuilderAnimationManager = cc.Class.extend({
3535 _autoPlaySequenceId :0 ,
3636
3737 _rootNode :null ,
38+ _owner :null ,
3839 _rootContainerSize :null ,
3940
4041 _delegate :null ,
@@ -46,6 +47,8 @@ cc.BuilderAnimationManager = cc.Class.extend({
4647 _documentCallbackNodes :null ,
4748 _documentControllerName :"" ,
4849 _lastCompletedSequenceName :"" ,
50+ _keyframeCallbacks :[ ] ,
51+ _keyframeCallfuncs :{ } ,
4952
5053 _animationCompleteCallbackFunc :null ,
5154 _target :null ,
@@ -86,6 +89,13 @@ cc.BuilderAnimationManager = cc.Class.extend({
8689 this . _rootNode = rootNode ;
8790 } ,
8891
92+ getOwner :function ( ) {
93+ return this . _owner ;
94+ } ,
95+ setOwner :function ( owner ) {
96+ this . _owner = owner ;
97+ } ,
98+
8999 addDocumentCallbackNode :function ( node ) {
90100 this . _documentCallbackNodes . push ( node ) ;
91101 } ,
@@ -183,6 +193,63 @@ cc.BuilderAnimationManager = cc.Class.extend({
183193 }
184194 } ,
185195
196+ getActionForCallbackChannel :function ( channel ) {
197+ var lastKeyframeTime = 0 ;
198+ var actions = [ ] ;
199+
200+ for ( var keyframe in channel . getKeyframes ( ) )
201+ {
202+ var timeSinceLastKeyframe = keyframe . getTime ( ) - lastKeyframeTime ;
203+ lastKeyframeTime = keyframe . getTime ( ) ;
204+ if ( timeSinceLastKeyframe > 0 )
205+ {
206+ actions . push ( cc . DelayTime . create ( timeSinceLastKeyframe ) ) ;
207+ }
208+
209+ var selectorName = keyframe . getValue ( ) [ 0 ] ;
210+ var selectorTarget = keyframe . getValue ( ) [ 1 ] ;
211+
212+ // Handle JS controlled timelines
213+ var callbackName = "" + selectorTarget + ":" + selectorName ;
214+ var callback = _keyframeCallFuncs [ callbackName ] ;
215+
216+ if ( callback )
217+ {
218+ actions . push ( callback ) ;
219+ }
220+ }
221+
222+ if ( ! actions . length )
223+ return null ;
224+
225+ return cc . Sequence . create ( actions ) ;
226+ } ,
227+ getActionForSoundChannel :function ( channel ) {
228+ var lastKeyframeTime = 0 ;
229+ var actions = [ ] ;
230+
231+ for ( var keyframe in channel . getKeyframes ( ) )
232+ {
233+ var timeSinceLastKeyframe = keyframe . getTime ( ) - lastKeyframeTime ;
234+ lastKeyframeTime = keyframe . getTime ( ) ;
235+ if ( timeSinceLastKeyframe > 0 )
236+ {
237+ actions . push ( cc . DelayTime . create ( timeSinceLastKeyframe ) ) ;
238+ }
239+
240+ var array = keyframe . getValue ( ) ;
241+ var soundFile = array [ 0 ] ;
242+ var pitch = array [ 1 ] ;
243+ var pan = array [ 2 ] ;
244+ var gain = array [ 3 ] ;
245+
246+ actions . push ( cc . BuilderSoundEffect . create ( soundFile , pitch , pan , gain ) ) ;
247+ }
248+
249+ if ( ! actions . length ) return null ;
250+
251+ return cc . Sequence . create ( actions ) ;
252+ } ,
186253 runAnimationsForSequenceNamed :function ( name ) {
187254 this . runAnimations ( name ) ;
188255 } ,
@@ -239,7 +306,26 @@ cc.BuilderAnimationManager = cc.Class.extend({
239306 var completeAction = cc . Sequence . create ( cc . DelayTime . create ( seq . getDuration ( ) + tweenDuration ) ,
240307 cc . CallFunc . create ( this . _sequenceCompleted , this ) ) ;
241308 this . _rootNode . runAction ( completeAction ) ;
242- // Set the running scene
309+
310+ // Playback callbacks and sounds
311+ if ( seq . getCallbackChannel ( ) ) {
312+ // Build sound actions for channel
313+ var action = this . getActionForCallbackChannel ( seq . getCallbackChannel ( ) ) ;
314+ if ( action )
315+ {
316+ this . _rootNode . runAction ( action ) ;
317+ }
318+ }
319+
320+ if ( seq . getSoundChannel ( ) ) {
321+ // Build sound actions for channel
322+ var action = this . getActionForSoundChannel ( seq . getSoundChannel ( ) ) ;
323+ if ( action )
324+ {
325+ this . _rootNode . runAction ( action ) ;
326+ }
327+ }
328+ // Set the running scene
243329 this . _runningSequence = this . _getSequence ( nSeqId ) ;
244330 } ,
245331
@@ -251,7 +337,9 @@ cc.BuilderAnimationManager = cc.Class.extend({
251337 setCompletedAnimationCallback :function ( target , callbackFunc ) {
252338 this . setAnimationCompletedCallback ( target , callbackFunc ) ;
253339 } ,
254-
340+ setCallFunc :function ( callFunc , callbackNamed ) {
341+ this . _keyframeCallFuncs [ callbackNamed ] = callFunc ;
342+ } ,
255343 debug :function ( ) {
256344 } ,
257345
@@ -288,6 +376,10 @@ cc.BuilderAnimationManager = cc.Class.extend({
288376
289377 if ( propName === "rotation" ) {
290378 return cc . BuilderRotateTo . create ( duration , keyframe1 . getValue ( ) ) ;
379+ } else if ( propName === "rotationX" ) {
380+ return cc . BuilderRotateXTo . create ( duration , keyframe1 . getValue ( ) ) ;
381+ } else if ( propName === "rotationY" ) {
382+ return cc . BuilderRotateYTo . create ( duration , keyframe1 . getValue ( ) ) ;
291383 } else if ( propName === "opacity" ) {
292384 return cc . FadeTo . create ( duration , keyframe1 . getValue ( ) ) ;
293385 } else if ( propName === "color" ) {
@@ -328,6 +420,12 @@ cc.BuilderAnimationManager = cc.Class.extend({
328420 if ( type == CCB_SCALETYPE_MULTIPLY_RESOLUTION )
329421 var resolutionScale = cc . BuilderReader . getResolutionScale ( ) ;
330422 return cc . ScaleTo . create ( duration , x , y ) ;
423+ } else if ( propName === "skew" ) {
424+ //get relative position
425+ getValueArr = keyframe1 . getValue ( ) ;
426+ x = getValueArr [ 0 ] ;
427+ y = getValueArr [ 1 ] ;
428+ return cc . SkewTo . create ( duration , x , y ) ;
331429 } else {
332430 cc . log ( "BuilderReader: Failed to create animation for property: " + propName ) ;
333431 }
@@ -363,6 +461,13 @@ cc.BuilderAnimationManager = cc.Class.extend({
363461 y = value [ 1 ] ;
364462
365463 cc . setRelativeScale ( node , x , y , nType , propName ) ;
464+ } else if ( propName === "skew" ) {
465+ getArr = this . _getBaseValue ( node , propName ) ;
466+ nType = getArr [ 2 ] ;
467+ x = value [ 0 ] ;
468+ y = value [ 1 ] ;
469+ node . setSkewX ( x ) ;
470+ node . setSkewY ( y ) ;
366471 } else {
367472 // [node setValue:value forKey:name];
368473 // TODO only handle rotation, opacity, displayFrame, color
@@ -588,6 +693,9 @@ cc.BuilderSetSpriteFrame.create = function (spriteFrame) {
588693 return null ;
589694} ;
590695
696+ //
697+ // cc.BuilderRotateTo
698+ //
591699cc . BuilderRotateTo = cc . ActionInterval . extend ( {
592700 _startAngle :0 ,
593701 _dstAngle :0 ,
@@ -619,4 +727,49 @@ cc.BuilderRotateTo.create = function (duration, angle) {
619727 return ret ;
620728 }
621729 return null ;
622- } ;
730+ } ;
731+
732+ //
733+ // cc.BuilderRotateXTo
734+ //
735+ cc . BuilderRotateXTo = cc . ActionInterval . extend ( {
736+ // TODO: rotationX is not implemented in HTML5
737+ } ) ;
738+
739+ cc . BuilderRotateXTo . create = function ( duration , angle ) {
740+ cc . Assert ( false , "rotationX not implemented in cocos2d-html5" ) ;
741+ return null ;
742+ } ;
743+
744+ //
745+ // cc.BuilderRotateYTo
746+ //
747+ cc . BuilderRotateYTo = cc . ActionInterval . extend ( {
748+ // TODO: rotationX is not implemented in HTML5
749+ } ) ;
750+
751+ cc . BuilderRotateYTo . create = function ( duration , angle ) {
752+ cc . Assert ( false , "rotationY not implemented in cocos2d-html5" ) ;
753+ return null ;
754+ } ;
755+
756+ //
757+ // cc.BuilderSoundEffect
758+ //
759+ cc . BuilderSoundEffect = cc . ActionInstant . extend ( {
760+ init :function ( file ) {
761+ this . _file = file ;
762+ } ,
763+ update :function ( dt ) {
764+ cc . AudioEngine . getInstance ( ) . playEffect ( this . _file ) ;
765+ }
766+ } ) ;
767+ cc . BuilderSoundEffect . create = function ( file , pitch , pan , gain ) {
768+ var ret = new cc . BuilderSoundEffect ( ) ;
769+ if ( ret ) {
770+ if ( ret . init ( file ) )
771+ return ret ;
772+ }
773+ return null ;
774+ } ;
775+
0 commit comments