@@ -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,9 +47,12 @@ cc.BuilderAnimationManager = cc.Class.extend({
4647 _documentCallbackNodes :null ,
4748 _documentControllerName :"" ,
4849 _lastCompletedSequenceName :"" ,
50+ _keyframeCallbacks :null ,
51+ _keyframeCallFuncs :null ,
4952
5053 _animationCompleteCallbackFunc :null ,
5154 _target :null ,
55+ _jsControlled :false ,
5256
5357 ctor :function ( ) {
5458 this . _rootContainerSize = cc . size ( 0 , 0 ) ;
@@ -65,13 +69,20 @@ cc.BuilderAnimationManager = cc.Class.extend({
6569 this . _documentCallbackNames = [ ] ;
6670 this . _documentCallbackNodes = [ ] ;
6771
72+ this . _keyframeCallbacks = [ ] ;
73+ this . _keyframeCallFuncs = { } ;
74+
6875 return true ;
6976 } ,
7077
7178 getSequences :function ( ) {
7279 return this . _sequences ;
7380 } ,
7481
82+ setSequences :function ( seqs ) {
83+ this . _sequences = seqs ;
84+ } ,
85+
7586 getAutoPlaySequenceId :function ( ) {
7687 return this . _autoPlaySequenceId ;
7788 } ,
@@ -86,6 +97,13 @@ cc.BuilderAnimationManager = cc.Class.extend({
8697 this . _rootNode = rootNode ;
8798 } ,
8899
100+ getOwner :function ( ) {
101+ return this . _owner ;
102+ } ,
103+ setOwner :function ( owner ) {
104+ this . _owner = owner ;
105+ } ,
106+
89107 addDocumentCallbackNode :function ( node ) {
90108 this . _documentCallbackNodes . push ( node ) ;
91109 } ,
@@ -130,6 +148,10 @@ cc.BuilderAnimationManager = cc.Class.extend({
130148 return this . _lastCompletedSequenceName ;
131149 } ,
132150
151+ getKeyframeCallbacks :function ( ) {
152+ return this . _keyframeCallbacks ;
153+ } ,
154+
133155 getRootContainerSize :function ( ) {
134156 return this . _rootContainerSize ;
135157 } ,
@@ -183,6 +205,87 @@ cc.BuilderAnimationManager = cc.Class.extend({
183205 }
184206 } ,
185207
208+ getActionForCallbackChannel :function ( channel ) {
209+ var lastKeyframeTime = 0 ;
210+
211+ var actions = [ ] ;
212+ var keyframes = channel . getKeyframes ( ) ;
213+ var numKeyframes = keyframes . length ;
214+
215+ for ( var i = 0 ; i < numKeyframes ; ++ i ) {
216+ var keyframe = keyframes [ i ] ;
217+ var timeSinceLastKeyframe = keyframe . getTime ( ) - lastKeyframeTime ;
218+ lastKeyframeTime = keyframe . getTime ( ) ;
219+ if ( timeSinceLastKeyframe > 0 ) {
220+ actions . push ( cc . DelayTime . create ( timeSinceLastKeyframe ) ) ;
221+ }
222+
223+ var keyVal = keyframe . getValue ( ) ;
224+ var selectorName = keyVal [ 0 ] ;
225+ var selectorTarget = keyVal [ 1 ] ;
226+
227+ if ( this . _jsControlled ) {
228+ var callbackName = selectorTarget + ":" + selectorName ; //add number to the stream
229+ var callback = this . _keyframeCallFuncs [ callbackName ] ;
230+
231+ if ( callback != null )
232+ actions . push ( callback ) ;
233+ } else {
234+ var target ;
235+ if ( selectorTarget == CCB_TARGETTYPE_DOCUMENTROOT )
236+ target = this . _rootNode ;
237+ else if ( selectorTarget == CCB_TARGETTYPE_OWNER )
238+ target = this . _owner ;
239+
240+ if ( target != null ) {
241+ if ( selectorName . length > 0 ) {
242+ var selCallFunc = 0 ;
243+
244+ var targetAsCCBSelectorResolver = target ;
245+
246+ if ( target . onResolveCCBCCCallFuncSelector != null )
247+ selCallFunc = targetAsCCBSelectorResolver . onResolveCCBCCCallFuncSelector ( target , selectorName ) ;
248+ if ( selCallFunc == 0 )
249+ cc . log ( "Skipping selector '" + selectorName + "' since no CCBSelectorResolver is present." ) ;
250+ else
251+ actions . push ( cc . CallFunc . create ( selCallFunc , target ) ) ;
252+ } else {
253+ cc . log ( "Unexpected empty selector." ) ;
254+ }
255+ }
256+ }
257+ }
258+ if ( actions . length < 1 )
259+ return null ;
260+
261+ return cc . Sequence . create ( actions ) ;
262+ } ,
263+ getActionForSoundChannel :function ( channel ) {
264+ var lastKeyframeTime = 0 ;
265+
266+ var actions = [ ] ;
267+ var keyframes = channel . getKeyframes ( ) ;
268+ var numKeyframes = keyframes . length ;
269+
270+ for ( var i = 0 ; i < numKeyframes ; ++ i ) {
271+ var keyframe = keyframes [ i ] ;
272+ var timeSinceLastKeyframe = keyframe . getTime ( ) - lastKeyframeTime ;
273+ lastKeyframeTime = keyframe . getTime ( ) ;
274+ if ( timeSinceLastKeyframe > 0 ) {
275+ actions . push ( cc . DelayTime . create ( timeSinceLastKeyframe ) ) ;
276+ }
277+
278+ var keyVal = keyframe . getValue ( ) ;
279+ var soundFile = cc . BuilderReader . getResourcePath ( ) + keyVal [ 0 ] ;
280+ var pitch = parseFloat ( keyVal [ 1 ] ) , pan = parseFloat ( keyVal [ 2 ] ) , gain = parseFloat ( keyVal [ 3 ] ) ;
281+ actions . push ( cc . BuilderSoundEffect . create ( soundFile , pitch , pan , gain ) ) ;
282+ }
283+
284+ if ( actions . length < 1 )
285+ return null ;
286+
287+ return cc . Sequence . create ( actions ) ;
288+ } ,
186289 runAnimationsForSequenceNamed :function ( name ) {
187290 this . runAnimations ( name ) ;
188291 } ,
@@ -239,7 +342,24 @@ cc.BuilderAnimationManager = cc.Class.extend({
239342 var completeAction = cc . Sequence . create ( cc . DelayTime . create ( seq . getDuration ( ) + tweenDuration ) ,
240343 cc . CallFunc . create ( this . _sequenceCompleted , this ) ) ;
241344 this . _rootNode . runAction ( completeAction ) ;
242- // Set the running scene
345+
346+ // Playback callbacks and sounds
347+ if ( seq . getCallbackChannel ( ) ) {
348+ // Build sound actions for channel
349+ var action = this . getActionForCallbackChannel ( seq . getCallbackChannel ( ) ) ;
350+ if ( action ) {
351+ this . _rootNode . runAction ( action ) ;
352+ }
353+ }
354+
355+ if ( seq . getSoundChannel ( ) ) {
356+ // Build sound actions for channel
357+ var action = this . getActionForSoundChannel ( seq . getSoundChannel ( ) ) ;
358+ if ( action ) {
359+ this . _rootNode . runAction ( action ) ;
360+ }
361+ }
362+ // Set the running scene
243363 this . _runningSequence = this . _getSequence ( nSeqId ) ;
244364 } ,
245365
@@ -251,7 +371,9 @@ cc.BuilderAnimationManager = cc.Class.extend({
251371 setCompletedAnimationCallback :function ( target , callbackFunc ) {
252372 this . setAnimationCompletedCallback ( target , callbackFunc ) ;
253373 } ,
254-
374+ setCallFunc :function ( callFunc , callbackNamed ) {
375+ this . _keyframeCallFuncs [ callbackNamed ] = callFunc ;
376+ } ,
255377 debug :function ( ) {
256378 } ,
257379
@@ -288,6 +410,10 @@ cc.BuilderAnimationManager = cc.Class.extend({
288410
289411 if ( propName === "rotation" ) {
290412 return cc . BuilderRotateTo . create ( duration , keyframe1 . getValue ( ) ) ;
413+ } else if ( propName === "rotationX" ) {
414+ return cc . BuilderRotateXTo . create ( duration , keyframe1 . getValue ( ) ) ;
415+ } else if ( propName === "rotationY" ) {
416+ return cc . BuilderRotateYTo . create ( duration , keyframe1 . getValue ( ) ) ;
291417 } else if ( propName === "opacity" ) {
292418 return cc . FadeTo . create ( duration , keyframe1 . getValue ( ) ) ;
293419 } else if ( propName === "color" ) {
@@ -328,6 +454,12 @@ cc.BuilderAnimationManager = cc.Class.extend({
328454 if ( type == CCB_SCALETYPE_MULTIPLY_RESOLUTION )
329455 var resolutionScale = cc . BuilderReader . getResolutionScale ( ) ;
330456 return cc . ScaleTo . create ( duration , x , y ) ;
457+ } else if ( propName === "skew" ) {
458+ //get relative position
459+ getValueArr = keyframe1 . getValue ( ) ;
460+ x = getValueArr [ 0 ] ;
461+ y = getValueArr [ 1 ] ;
462+ return cc . SkewTo . create ( duration , x , y ) ;
331463 } else {
332464 cc . log ( "BuilderReader: Failed to create animation for property: " + propName ) ;
333465 }
@@ -363,6 +495,13 @@ cc.BuilderAnimationManager = cc.Class.extend({
363495 y = value [ 1 ] ;
364496
365497 cc . setRelativeScale ( node , x , y , nType , propName ) ;
498+ } else if ( propName === "skew" ) {
499+ getArr = this . _getBaseValue ( node , propName ) ;
500+ nType = getArr [ 2 ] ;
501+ x = value [ 0 ] ;
502+ y = value [ 1 ] ;
503+ node . setSkewX ( x ) ;
504+ node . setSkewY ( y ) ;
366505 } else {
367506 // [node setValue:value forKey:name];
368507 // TODO only handle rotation, opacity, displayFrame, color
@@ -588,6 +727,9 @@ cc.BuilderSetSpriteFrame.create = function (spriteFrame) {
588727 return null ;
589728} ;
590729
730+ //
731+ // cc.BuilderRotateTo
732+ //
591733cc . BuilderRotateTo = cc . ActionInterval . extend ( {
592734 _startAngle :0 ,
593735 _dstAngle :0 ,
@@ -619,4 +761,49 @@ cc.BuilderRotateTo.create = function (duration, angle) {
619761 return ret ;
620762 }
621763 return null ;
622- } ;
764+ } ;
765+
766+ //
767+ // cc.BuilderRotateXTo
768+ //
769+ cc . BuilderRotateXTo = cc . ActionInterval . extend ( {
770+ // TODO: rotationX is not implemented in HTML5
771+ } ) ;
772+
773+ cc . BuilderRotateXTo . create = function ( duration , angle ) {
774+ cc . Assert ( false , "rotationX not implemented in cocos2d-html5" ) ;
775+ return null ;
776+ } ;
777+
778+ //
779+ // cc.BuilderRotateYTo
780+ //
781+ cc . BuilderRotateYTo = cc . ActionInterval . extend ( {
782+ // TODO: rotationX is not implemented in HTML5
783+ } ) ;
784+
785+ cc . BuilderRotateYTo . create = function ( duration , angle ) {
786+ cc . Assert ( false , "rotationY not implemented in cocos2d-html5" ) ;
787+ return null ;
788+ } ;
789+
790+ //
791+ // cc.BuilderSoundEffect
792+ //
793+ cc . BuilderSoundEffect = cc . ActionInstant . extend ( {
794+ init :function ( file ) {
795+ this . _file = file ;
796+ return true ;
797+ } ,
798+ update :function ( dt ) {
799+ cc . AudioEngine . getInstance ( ) . playEffect ( this . _file ) ;
800+ }
801+ } ) ;
802+ cc . BuilderSoundEffect . create = function ( file , pitch , pan , gain ) {
803+ var ret = new cc . BuilderSoundEffect ( ) ;
804+ if ( ret && ret . init ( file ) ) {
805+ return ret ;
806+ }
807+ return null ;
808+ } ;
809+
0 commit comments