Fork me on GitHub

API Documentation


Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_animation_glge_action.js.html, line: 82 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_animation_glge_action.js.html, line: 82 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_animation_glge_action.js.html, line: 89 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29

Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in jsdoc/symbols/src/src_animation_glge_action.js.html, line: 89 in /homepages/22/d163487924/htdocs/glge/wp-content/themes/glge/manual.php on line 29
  1 /*
  2 GLGE WebGL Graphics Engine
  3 Copyright (c) 2010, Paul Brunt
  4 All rights reserved.
  5 
  6 Redistribution and use in source and binary forms, with or without
  7 modification, are permitted provided that the following conditions are met:
  8     * Redistributions of source code must retain the above copyright
  9       notice, this list of conditions and the following disclaimer.
 10     * Redistributions in binary form must reproduce the above copyright
 11       notice, this list of conditions and the following disclaimer in the
 12       documentation and/or other materials provided with the distribution.
 13     * Neither the name of GLGE nor the
 14       names of its contributors may be used to endorse or promote products
 15       derived from this software without specific prior written permission.
 16 
 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 20 DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY
 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 */
 28 
 29 /**
 30  * @fileOverview
 31  * @name glge_action.js
 32  * @author me@paulbrunt.co.uk
 33  */
 34 
 35 
 36 (function(GLGE){
 37 
 38 
 39 
 40 /**
 41 * @class Class to describe and action on a skeleton
 42 * @param {string} uid a unique reference string for this object
 43 * @augments GLGE.QuickNotation
 44 * @augments GLGE.JSONLoader
 45 */
 46 GLGE.Action=function(uid){
 47 	this.channels=[];
 48 	GLGE.Assets.registerAsset(this,uid);
 49 };
 50 GLGE.augment(GLGE.QuickNotation,GLGE.Action);
 51 GLGE.augment(GLGE.JSONLoader,GLGE.Action);
 52 /**
 53  * @name Action#animFinished
 54  * @event
 55  * @param {object} data
 56  */
 57 GLGE.augment(GLGE.Events,GLGE.Action);
 58 
 59 /**
 60 * Starts playing the action
 61 */
 62 GLGE.Action.prototype.start=function(blendTime,loop,names){
 63 	if(!loop) loop=false;
 64 	if(!blendTime) blendTime=0;
 65 	var channels=this.channels;
 66 	var start=(new Date()).getTime();
 67 	this.animFinished=false;
 68 	
 69 	for(var i=0;i<channels.length;i++){
 70 		var animation=channels[i].getAnimation();
 71 		var action=this;
 72 		var channel=channels[i];
 73 		var target=channel.getTarget();
 74 		if(typeof target=="string"){
 75 			if(names && names[target]){
 76 				target=names[target];
 77 			}
 78 		}
 79 		var closure={};
 80 		closure.finishEvent=function(data){
 81 			target.removeEventListener("animFinished",closure.finishEvent);
 82 			if(!action.animFinished && target.animation==animation){
 83 				action.fireEvent("animFinished",{});
 84 				action.animFinished=true;
 85  86 			}
 87 		}
 88 		target.addEventListener("animFinished",closure.finishEvent);
 89 		
 90 		target.setAnimation(animation,blendTime,start);
 91 		target.setLoop(loop);
 92 
 93 	}
 94 };
 95 /**
 96 * Sets the start frame for all animations
 97 * @param {number} startFrame the starting frame for the animation
 98 */
 99 GLGE.Action.prototype.setStartFrame=function(startFrame){
100 	for(var i=0;i<this.channels.length;i++){
101 		this.channels[i].getAnimation().setStartFrame(startFrame);
102 	}
103 	return this;
104 };
105 /**
106 * Sets the number of frames to play
107 * @param {number} frame the number of frames to play
108 */
109 GLGE.Action.prototype.setFrames=function(frames){
110 	for(var i=0;i<this.channels.length;i++){
111 		this.channels[i].getAnimation().setFrames(frames);
112 	}
113 	return this;
114 };
115 
116 
117 /**
118 * Adds and action channel to this action
119 * @param {GLGE.ActionChannel} channel the channel to be added
120 */
121 GLGE.Action.prototype.addActionChannel=function(channel){
122 	this.channels.push(channel);
123 	return this;
124 };
125 /**
126 * Removes and action channel to this action
127 * @param {GLGE.ActionChannel} channel the channel to be removed
128 */
129 GLGE.Action.prototype.removeActionChannel=function(channel){
130 	for(var i=0;i<this.channels.length;i++){
131 		if(this.channels[i]==channels){
132 			this.channels.splice(i,1);
133 			break;
134 		}
135 	}
136 };
137 
138 
139 })(GLGE);
140