1 /**************************************************************************** 2 Copyright (c) 2008-2010 Ricardo Quesada 3 Copyright (c) 2011-2012 cocos2d-x.org 4 Copyright (c) 2013-2014 Chukong Technologies Inc. 5 6 http://www.cocos2d-x.org 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this software and associated documentation files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE. 25 ****************************************************************************/ 26 27 /** 28 * @class 29 * @extends cc.Class 30 */ 31 cc.ActionTweenDelegate = cc.Class.extend(/** @lends cc.ActionTweenDelegate */{ 32 updateTweenAction:function(value, key){ 33 34 } 35 }); 36 37 /** 38 * cc.ActionTween 39 * cc.ActionTween is an action that lets you update any property of an object. 40 * 41 * @class 42 * @extends cc.ActionInterval 43 * @example 44 * //For example, if you want to modify the "width" property of a target from 200 to 300 in 2 seconds, then: 45 * var modifyWidth = cc.ActionTween.create(2,"width",200,300) 46 * target.runAction(modifyWidth); 47 * 48 * //Another example: cc.ScaleTo action could be rewriten using cc.PropertyAction: 49 * // scaleA and scaleB are equivalents 50 * var scaleA = cc.ScaleTo.create(2,3); 51 * var scaleB = cc.ActionTween.create(2,"scale",1,3); 52 */ 53 cc.ActionTween = cc.ActionInterval.extend(/** @lends cc.ActionTween */{ 54 key:"", 55 from:0, 56 to:0, 57 delta:0, 58 59 /** 60 * Creates an initializes the action with the property name (key), and the from and to parameters. 61 * Constructor of cc.ActionTween 62 * @param {Number} duration 63 * @param {String} key 64 * @param {Number} from 65 * @param {Number} to 66 */ 67 ctor:function(duration, key, from, to){ 68 cc.ActionInterval.prototype.ctor.call(this); 69 this.key = ""; 70 71 to !== undefined && this.initWithDuration(duration, key, from, to); 72 }, 73 74 /** 75 * initializes the action with the property name (key), and the from and to parameters. 76 * @param {Number} duration 77 * @param {String} key 78 * @param {Number} from 79 * @param {Number} to 80 * @return {Boolean} 81 */ 82 initWithDuration:function (duration, key, from, to) { 83 if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) { 84 this.key = key; 85 this.to = to; 86 this.from = from; 87 return true; 88 } 89 return false; 90 }, 91 /** 92 * @param {cc.Node} target 93 */ 94 startWithTarget:function (target) { 95 if(!target || !target.updateTweenAction) 96 throw "cc.ActionTween.startWithTarget(): target must be non-null, and target must implement updateTweenAction function"; 97 cc.ActionInterval.prototype.startWithTarget.call(this, target); 98 this.delta = this.to - this.from; 99 }, 100 /** 101 * @param {Number} dt 102 */ 103 update:function (dt) { 104 this.target.updateTweenAction(this.to - this.delta * (1 - dt), this.key); 105 }, 106 /** 107 * @return {cc.ActionTween} 108 */ 109 reverse:function () { 110 return cc.ActionTween.create(this.duration, this.key, this.to, this.from); 111 }, 112 113 clone:function(){ 114 var action = new cc.ActionTween(); 115 action.initWithDuration(this._duration, this.key, this.from, this.to); 116 return action; 117 } 118 }); 119 120 /** 121 * Creates an initializes the action with the property name (key), and the from and to parameters. 122 * @param {Number} duration 123 * @param {String} key 124 * @param {Number} from 125 * @param {Number} to 126 * @return {cc.ActionTween} 127 */ 128 cc.ActionTween.create = function (duration, key, from, to) { 129 var ret = new cc.ActionTween(); 130 if (ret.initWithDuration(duration, key, from, to)) 131 return ret; 132 return null; 133 }; 134 135 cc.action = cc.Action.create; 136 cc.speed = cc.Speed.create; 137 cc.follow = cc.Follow.create; 138 cc.orbitCamera = cc.OrbitCamera.create; 139 cc.cardinalSplineTo = cc.CardinalSplineTo.create; 140 cc.cardinalSplineBy = cc.CardinalSplineBy.create; 141 cc.catmullRomTo = cc.CatmullRomTo.create; 142 cc.catmullRomBy = cc.CatmullRomBy.create; 143 cc.show = cc.Show.create; 144 cc.hide = cc.Hide.create; 145 cc.toggleVisibility = cc.ToggleVisibility.create; 146 cc.removeSelf = cc.RemoveSelf.create; 147 cc.flipX = cc.FlipX.create; 148 cc.flipY = cc.FlipY.create; 149 cc.place = cc.Place.create; 150 cc.callFunc = cc.CallFunc.create; 151 cc.actionInterval = cc.ActionInterval.create; 152 cc.sequence = cc.Sequence.create; 153 cc.repeat = cc.Repeat.create; 154 cc.repeatForever = cc.RepeatForever.create; 155 cc.spawn = cc.Spawn.create; 156 cc.rotateTo = cc.RotateTo.create; 157 cc.rotateBy = cc.RotateBy.create; 158 cc.moveBy = cc.MoveBy.create; 159 cc.moveTo = cc.MoveTo.create; 160 cc.skewTo = cc.SkewTo.create; 161 cc.skewBy = cc.SkewBy.create; 162 cc.jumpBy = cc.JumpBy.create; 163 cc.jumpTo = cc.JumpTo.create; 164 cc.bezierBy = cc.BezierBy.create; 165 cc.bezierTo = cc.BezierTo.create; 166 cc.scaleTo = cc.ScaleTo.create; 167 cc.scaleBy = cc.ScaleBy.create; 168 cc.blink = cc.Blink.create; 169 cc.fadeTo = cc.FadeTo.create; 170 cc.fadeIn = cc.FadeIn.create; 171 cc.fadeOut = cc.FadeOut.create; 172 cc.tintTo = cc.TintTo.create; 173 cc.tintBy = cc.TintBy.create; 174 cc.delayTime = cc.DelayTime.create; 175 cc.reverseTime = cc.ReverseTime.create; 176 cc.animate = cc.Animate.create; 177 cc.targetedAction = cc.TargetedAction.create; 178 cc.actionTween = cc.ActionTween.create;