* @function LevelRenderer.Render.prototype.animate * @description 动画。 * * @example * zr.animate(circle.id, 'style', false) * .when(1000, {x: 10} ) * .done(function(){ // Animation done }) * .start() * * * @param {Array.<(L
(el, path, loop)
| 310 | * @return {LevelRenderer.animation.Animator} Animator。 |
| 311 | */ |
| 312 | animate(el, path, loop) { |
| 313 | if (typeof(el) === 'string') { |
| 314 | el = this.storage.get(el); |
| 315 | } |
| 316 | if (el) { |
| 317 | var target; |
| 318 | if (path) { |
| 319 | var pathSplitted = path.split('.'); |
| 320 | var prop = el; |
| 321 | for (var i = 0, l = pathSplitted.length; i < l; i++) { |
| 322 | if (!prop) { |
| 323 | continue; |
| 324 | } |
| 325 | prop = prop[pathSplitted[i]]; |
| 326 | } |
| 327 | if (prop) { |
| 328 | target = prop; |
| 329 | } |
| 330 | } else { |
| 331 | target = el; |
| 332 | } |
| 333 | |
| 334 | if (!target) { |
| 335 | SUtil.Util_log( |
| 336 | 'Property "' |
| 337 | + path |
| 338 | + '" is not existed in element ' |
| 339 | + el.id |
| 340 | ); |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | var animatingElements = this.animatingElements; |
| 345 | if (typeof el.__aniCount === 'undefined') { |
| 346 | // 正在进行的动画记数 |
| 347 | el.__aniCount = 0; |
| 348 | } |
| 349 | if (el.__aniCount === 0) { |
| 350 | animatingElements.push(el); |
| 351 | } |
| 352 | el.__aniCount++; |
| 353 | |
| 354 | return this.animation.animate(target, {loop: loop}) |
| 355 | .done(function () { |
| 356 | el.__aniCount--; |
| 357 | if (el.__aniCount === 0) { |
| 358 | // 从animatingElements里移除 |
| 359 | var idx = new Util().indexOf(animatingElements, el); |
| 360 | animatingElements.splice(idx, 1); |
| 361 | } |
| 362 | }); |
| 363 | } else { |
| 364 | SUtil.Util_log('Element not existed'); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * @function LevelRenderer.Render.prototype.clearAnimation |