Merge branch 'v1.0' of github.com:fireball-x/engine into v1.0

This commit is contained in:
knoxHuang
2016-03-18 13:39:35 +08:00
20 changed files with 280 additions and 213 deletions
+1 -5
View File
@@ -58,11 +58,7 @@ _p = null;
* @name cc.ENGINE_VERSION
*/
var engineVersion;
if (CC_EDITOR) {
engineVersion = 'Cocos Creator v' + Editor.remote.versions.CocosCreator;
} else {
engineVersion = 'Cocos Creator';
}
engineVersion = '0.8.0-beta.7';
window['CocosEngine'] = cc.ENGINE_VERSION = engineVersion;
/**
+15 -7
View File
@@ -471,7 +471,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
* @param {Function} [onLaunched] - The function invoked at the scene after launch.
*/
runSceneImmediate: function (scene, onBeforeLoadScene, onLaunched) {
var i, node, game = cc.game;
var id, node, game = cc.game;
var persistNodes = game._persistRootNodes;
if (scene instanceof cc.Scene) {
@@ -480,8 +480,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
}
// detach persist nodes
for (i = persistNodes.length - 1; i >= 0; --i) {
node = persistNodes[i];
for (id in persistNodes) {
node = persistNodes[id];
game._ignoreRemovePersistNode = node;
node.parent = null;
game._ignoreRemovePersistNode = null;
@@ -510,10 +510,18 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
this._scene = scene;
sgScene = scene._sgNode;
// Re-attach persist nodes
for (i = 0; i < persistNodes.length; ++i) {
node = persistNodes[i];
node.parent = scene;
// Re-attach or replace persist nodes
for (id in persistNodes) {
node = persistNodes[id];
var existNode = scene.getChildByUuid(id);
// Scene contains the persist node, should not reattach, should update the persist node
if (existNode) {
persistNodes[id] = existNode;
existNode._persistNode = true;
}
else {
node.parent = scene;
}
}
scene._activate();
}
+11 -9
View File
@@ -47,7 +47,7 @@ var game = /** @lends cc.game# */{
_eventHide: null,
_eventShow: null,
_persistRootNodes: [],
_persistRootNodes: {},
_ignoreRemovePersistNode: null,
/**
@@ -343,10 +343,12 @@ var game = /** @lends cc.game# */{
* @param {Node} node - The node to be made persistent
*/
addPersistRootNode: function (node) {
if (!(node instanceof cc.Node))
if (!(node instanceof cc.Node) || !node.uuid) {
cc.warn('The target can not be made persist because it\'s not a cc.Node or it doesn\'t have _id property.');
return;
var index = this._persistRootNodes.indexOf(node);
if (index === -1) {
}
var id = node.uuid;
if (!this._persistRootNodes[id]) {
var scene = cc.director._scene;
if (cc.isValid(scene)) {
if (!node.parent) {
@@ -360,7 +362,7 @@ var game = /** @lends cc.game# */{
cc.warn('The node can not be made persist because it\'s not in current scene.');
return;
}
this._persistRootNodes.push(node);
this._persistRootNodes[id] = node;
node._persistNode = true;
}
}
@@ -373,11 +375,11 @@ var game = /** @lends cc.game# */{
*/
removePersistRootNode: function (node) {
if (node !== this._ignoreRemovePersistNode) {
var index = this._persistRootNodes.indexOf(node);
if (index !== -1) {
this._persistRootNodes.splice(index, 1);
var id = node.uuid || '';
if (node === this._persistRootNodes[id]) {
delete this._persistRootNodes[id];
node._persistNode = false;
}
node._persistNode = false;
}
},
+3 -3
View File
@@ -1056,7 +1056,7 @@ var Node = cc.Class({
},
_checkTouchListeners: function () {
if (this._bubblingListeners && this._touchListener) {
if (!(this._objFlags & Destroying) && this._bubblingListeners && this._touchListener) {
for (var i = 0; i < _touchEvents.length; ++i) {
if (this._bubblingListeners.has(_touchEvents[i])) {
return;
@@ -1068,7 +1068,7 @@ var Node = cc.Class({
}
},
_checkMouseListeners: function () {
if (this._bubblingListeners && this._mouseListener) {
if (!(this._objFlags & Destroying) && this._bubblingListeners && this._mouseListener) {
for (var i = 0; i < _mouseEvents.length; ++i) {
if (this._bubblingListeners.has(_mouseEvents[i])) {
return;
@@ -1126,7 +1126,7 @@ var Node = cc.Class({
},
isRunning: function () {
return this.active;
return this._activeInHierarchy;
},
// ACTIONS
+32 -64
View File
@@ -172,7 +172,7 @@ var TimerTargetSelector = Timer.extend({
this._selector = null;
},
initWithSelector: function(scheduler, selector, target, seconds, repeat, delay){
initWithSelector: function(scheduler, target, selector, seconds, repeat, delay){
this._scheduler = scheduler;
this._target = target;
this._selector = selector;
@@ -186,8 +186,8 @@ var TimerTargetSelector = Timer.extend({
trigger: function(){
//override
if (this._target && this._selector){
this._target.call(this._selector, this._elapsed);
if (this._selector && this._target){
this._selector.call(this._target, this._elapsed);
}
},
@@ -512,7 +512,7 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
*/
scheduleCallbackForTarget: function(target, callback_fn, interval, repeat, delay, paused){
//cc.log("scheduleCallbackForTarget is deprecated. Please use schedule.");
this.schedule(callback_fn, target, interval, repeat, delay, paused, getTargetId(target) + "");
this.schedule(callback_fn, target, interval, repeat, delay, paused);
},
/**
@@ -524,36 +524,21 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
* @param {Number} repeat
* @param {Number} delay
* @param {Boolean} paused
* @param {Number} key
* @example {@link utils/api/engine/docs/cocos2d/core/CCScheduler/schedule.js}
*/
schedule: function(callback, target, interval, repeat, delay, paused, key){
var isSelector = false;
if(typeof callback !== "function"){
var selector = callback;
isSelector = true;
schedule: function (callback, target, interval, repeat, delay, paused) {
'use strict';
if (typeof callback !== 'function') {
var tmp = callback;
callback = target;
target = tmp;
}
if(isSelector === false){
//callback, target, interval, repeat, delay, paused, key
//callback, target, interval, paused, key
if(arguments.length === 4 || arguments.length === 5){
key = delay;
paused = repeat;
delay = 0;
repeat = cc.macro.REPEAT_FOREVER;
}
}else{
//selector, target, interval, repeat, delay, paused
//selector, target, interval, paused
if(arguments.length === 4){
paused = repeat;
repeat = cc.macro.REPEAT_FOREVER;
delay = 0;
}
}
if (key === undefined) {
key = target.__instanceId + "";
//selector, target, interval, repeat, delay, paused
//selector, target, interval, paused
if(arguments.length === 4 || arguments.length === 5){
paused = repeat;
repeat = cc.macro.REPEAT_FOREVER;
delay = 0;
}
cc.assert(target, cc._LogInfos.Scheduler_scheduleCallbackForTarget_3);
@@ -567,42 +552,27 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
this._arrayForTimers.push(element);
this._hashForTimers[instanceId] = element;
}else{
cc.assert(element.paused === paused, "");
cc.assert(element.paused === paused, '');
}
var timer, i;
if (element.timers == null) {
element.timers = [];
} else if(isSelector === false) {
for (i = 0; i < element.timers.length; i++) {
timer = element.timers[i];
if (callback === timer._callback) {
cc.log(cc._LogInfos.Scheduler.scheduleCallbackForTarget, timer.getInterval().toFixed(4), interval.toFixed(4));
timer._interval = interval;
return;
}
}
}else{
}
else {
for (i = 0; i < element.timers.length; ++i){
timer =element.timers[i];
if (timer && selector === timer.getSelector()){
cc.log("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: %.4f to %.4f", timer.getInterval(), interval);
if (timer && callback === timer.getSelector()){
cc.log('CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: %.4f to %.4f', timer.getInterval(), interval);
timer.setInterval(interval);
return;
}
}
//ccArrayEnsureExtraCapacity(element->timers, 1);
}
if(isSelector === false){
timer = new TimerTargetCallback();
timer.initWithCallback(this, callback, target, key, interval, repeat, delay);
element.timers.push(timer);
}else{
timer = new TimerTargetSelector();
timer.initWithSelector(this, selector, target, interval, repeat, delay);
element.timers.push(timer);
}
timer = new TimerTargetSelector();
timer.initWithSelector(this, target, callback, interval, repeat, delay);
element.timers.push(timer);
},
scheduleUpdate: function(target, priority, paused, updateFunc){
@@ -617,24 +587,22 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
case "string":
return key === timer.getKey();
case "function":
return key === timer._callback;
default:
return key === timer.getSelector();
return key === timer._callback || timer.getSelector();
}
},
/** Unschedules a callback for a callback and a given target.
* If you want to unschedule the "update", use `unscheudleUpdate()`
* @param {Function|String} key The callback to be unscheduled
* @param {Function} callback The callback to be unscheduled
* @param {Object} target The target bound to the callback.
*/
unschedule: function(key, target){
unschedule: function(callback, target){
//key, target
//selector, target
//callback, target - This is in order to increase compatibility
// explicity handle nil arguments when removing an object
if (!target || !key)
if (!target || !callback)
return;
var self = this, element = self._hashForTimers[getTargetId(target)];
@@ -642,7 +610,7 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
var timers = element.timers;
for(var i = 0, li = timers.length; i < li; i++){
var timer = timers[i];
if (this._getUnscheduleMark(key, timer)) {
if (this._getUnscheduleMark(callback, timer)) {
if ((timer === element.currentTimer) && (!element.currentTimerSalvaged)) {
element.currentTimerSalvaged = true;
}
@@ -1017,12 +985,12 @@ cc.Scheduler = cc._Class.extend(/** @lends cc.Scheduler# */{
/**
* Unschedules all function callbacks for a given target. This also includes the "update" callback function.
* @method unscheduleAllCallbacksForTarget
* @deprecated since v3.4 please use .unscheduleAll
* @deprecated since v3.4 please use unscheduleAllForTarget
* @param {Object} target
*/
unscheduleAllCallbacksForTarget: function(target){
//cc.log("unscheduleAllCallbacksForTarget is deprecated. Please use unscheduleAll.");
this.unschedule(getTargetId(target) + "", target);
this.unscheduleAllForTarget(target);
},
/**
@@ -36,14 +36,14 @@ cc.CustomRenderCmd = function (target, func) {
};
_ccsg.Node._dirtyFlags = {
transformDirty: 1 << 0,
visibleDirty: 1 << 1,
colorDirty: 1 << 2,
opacityDirty: 1 << 3,
cacheDirty: 1 << 4,
orderDirty: 1 << 5,
textDirty: 1 << 6,
gradientDirty:1 << 7,
transformDirty: 1 << 0,
visibleDirty: 1 << 1,
colorDirty: 1 << 2,
opacityDirty: 1 << 3,
cacheDirty: 1 << 4,
orderDirty: 1 << 5,
textDirty: 1 << 6,
gradientDirty: 1 << 7,
COUNT: 8
};
cc.js.get(_ccsg.Node._dirtyFlags, 'all', function () {
@@ -375,7 +375,7 @@ _ccsg.Node.RenderCmd.prototype = {
if (transformDirty)
//update the transform
this.transform(parentCmd, true);
this.transform(parentCmd);
},
visitChildren: function(){
+5 -1
View File
@@ -156,8 +156,12 @@ var Animation = cc.Class({
}
},
onEnable: function () {
this.resume();
},
onDisable: function () {
this.stop();
this.pause();
},
///////////////////////////////////////////////////////////////////////////////
+1 -1
View File
@@ -701,7 +701,7 @@ var Component = cc.Class({
repeat = isNaN(repeat) ? cc.macro.REPEAT_FOREVER : repeat;
delay = delay || 0;
cc.director.getScheduler().schedule(callback, this, interval, repeat, delay, !this.enabledInHierarchy, this.__instanceId);
cc.director.getScheduler().schedule(callback, this, interval, repeat, delay, !this.enabledInHierarchy);
},
/**
+3 -3
View File
@@ -420,6 +420,9 @@ var EditBox = cc.Class({
this._createBackgroundSprite();
if (!this._useOriginalSize) {
sgNode.setContentSize(this.node.getContentSize());
}
sgNode.inputMode = this.inputMode;
sgNode.maxLength = this.maxLength;
@@ -434,9 +437,6 @@ var EditBox = cc.Class({
sgNode.returnType = this.returnType;
sgNode.setLineHeight(this.lineHeight);
if (!this._useOriginalSize) {
sgNode.setContentSize(this.node.getContentSize());
}
sgNode.setDelegate(this);
},
+1 -1
View File
@@ -105,7 +105,7 @@ var RendererInSG = cc.Class({
parentNode.removeChild(replaced);
parentNode.addChild(sgNode);
sgNode.arrivalOrder = replaced.arrivalOrder;
if (cc.renderer) {
if ( !CC_JSB ) {
cc.renderer.childrenOrderDirty = parentNode._reorderChildDirty = true;
}
+6 -10
View File
@@ -115,7 +115,6 @@ _ccsg.Label = _ccsg.Node.extend({
_blendFunc: null,
_isUseSystemFont: true,
_labelSkinDirty: true,
_labelType: 0, //0 is ttf, 1 is bmfont.
_fontHandle: "", //a ttf font name or a bmfont file path.
_lineSpacing: 0,
@@ -436,16 +435,16 @@ _ccsg.Label = _ccsg.Node.extend({
_notifyLabelSkinDirty: function() {
if (CC_EDITOR) {
this._updateLabel();
this._labelSkinDirty = false;
} else {
this._labelSkinDirty = true;
this._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.textDirty);
}
},
_createRenderCmd: function() {
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL)
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
return new _ccsg.Label.WebGLRenderCmd(this);
else
} else {
return new _ccsg.Label.CanvasRenderCmd(this);
}
},
getContentSize: function() {
@@ -791,10 +790,10 @@ cc.BMFontHelper = {
var contentSize = cc.size(this._labelWidth, this._labelHeight);
if (this._labelWidth <= 0) {
contentSize.width = longestLine;
contentSize.width = parseFloat(longestLine.toFixed(2));
}
if (this._labelHeight <= 0) {
contentSize.height = this._textDesiredHeight;
contentSize.height = parseFloat(this._textDesiredHeight.toFixed(2));
}
_ccsg.Node.prototype.setContentSize.call(this, contentSize);
@@ -916,9 +915,6 @@ cc.BMFontHelper = {
this._computeHorizontalKerningForText(this._string);
updateFinished = this._alignText();
}
if (updateFinished) {
this._labelSkinDirty = false;
}
},
+99 -76
View File
@@ -31,6 +31,58 @@
var proto = _ccsg.Label.TTFLabelBaker.prototype = Object.create(Object.prototype);
proto.updateStatus = function () {
var flags = _ccsg.Node._dirtyFlags, locFlag = this._dirtyFlag;
var colorDirty = locFlag & flags.colorDirty,
opacityDirty = locFlag & flags.opacityDirty;
if (colorDirty)
this._updateDisplayColor();
if (opacityDirty)
this._updateDisplayOpacity();
if(colorDirty || opacityDirty || (locFlag & flags.textDirty)){
this._rebuildLabelSkin();
}
if (this._dirtyFlag & flags.transformDirty){
this.transform(this.getParentRenderCmd(), true);
this._dirtyFlag = this._dirtyFlag & _ccsg.Node._dirtyFlags.transformDirty ^ this._dirtyFlag;
}
};
proto._syncStatus = function (parentCmd) {
var flags = _ccsg.Node._dirtyFlags, locFlag = this._dirtyFlag;
var parentNode = parentCmd ? parentCmd._node : null;
if(parentNode && parentNode._cascadeColorEnabled && (parentCmd._dirtyFlag & flags.colorDirty))
locFlag |= flags.colorDirty;
if(parentNode && parentNode._cascadeOpacityEnabled && (parentCmd._dirtyFlag & flags.opacityDirty))
locFlag |= flags.opacityDirty;
if(parentCmd && (parentCmd._dirtyFlag & flags.transformDirty))
locFlag |= flags.transformDirty;
var colorDirty = locFlag & flags.colorDirty,
opacityDirty = locFlag & flags.opacityDirty;
this._dirtyFlag = locFlag;
if (colorDirty)
this._syncDisplayColor();
if (opacityDirty)
this._syncDisplayOpacity();
if(colorDirty || opacityDirty || (locFlag & flags.textDirty)){
this._rebuildLabelSkin();
}
if (locFlag & flags.transformDirty) //update the transform
this.transform(parentCmd);
};
proto._getLineHeight = function () {
var nodeSpacingY = this._node.getLineHeight();
if (nodeSpacingY === 0) {
@@ -162,38 +214,8 @@
return wrappedWords;
};
proto._updateDisplayOpacity = function (parentOpacity) {
_ccsg.Node.RenderCmd.prototype._updateDisplayOpacity.call(this, parentOpacity);
var node = this._node;
if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) {
//specify opacity to quad
var color = cc.color(255, 255, 255, this._displayedOpacity);
var quad = this._quad;
quad._bl.colors = color;
quad._br.colors = color;
quad._tl.colors = color;
quad._tr.colors = color;
this._quadDirty = true;
}
};
proto._updateDisplayColor = function (parentColor) {
_ccsg.Node.RenderCmd.prototype._updateDisplayColor.call(this, parentColor);
var node = this._node;
if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) {
node._labelSkinDirty = true;
}
};
proto._syncDisplayColor = function (parentColor) {
_ccsg.Node.RenderCmd.prototype._syncDisplayColor.call(this, parentColor);
var node = this._node;
if (node._labelType === _ccsg.Label.Type.TTF || node._labelType === _ccsg.Label.Type.SystemFont) {
node._labelSkinDirty = true;
}
};
proto._calculateLabelFont = function(canvasSize) {
proto._calculateLabelFont = function() {
var node = this._node;
var paragraphedStrings = node._string.split('\n');
@@ -212,9 +234,9 @@
if (node._isWrapText) {
var totalLength = 0;
for (i = 0; i < paragraphedStrings.length; ++i) {
totalLength += ((paragraphLength[i] / canvasSize.width + 1) | 0) * canvasSize.width;
totalLength += ((paragraphLength[i] / this._canvasSize.width + 1) | 0) * this._canvasSize.width;
}
var scale = canvasSize.width * ((canvasSize.height / this._getLineHeight()) | 0) / totalLength;
var scale = this._canvasSize.width * ((this._canvasSize.height / this._getLineHeight()) | 0) / totalLength;
this._drawFontsize = (this._drawFontsize * Math.min(Math.sqrt(scale), 1)) | 0;
fontDesc = this._drawFontsize.toString() + 'px ' + fontFamily;
this._labelContext.font = fontDesc;
@@ -226,8 +248,8 @@
for (i = 0; i < paragraphedStrings.length; ++i) {
if (maxLength < paragraphLength[i]) maxLength = paragraphLength[i];
}
var scaleX = canvasSize.width / maxLength;
var scaleY = canvasSize.height / totalHeight;
var scaleX = this._canvasSize.width / maxLength;
var scaleY = this._canvasSize.height / totalHeight;
this._drawFontsize = (this._drawFontsize * Math.min(1, scaleX, scaleY)) | 0;
fontDesc = this._drawFontsize.toString() + 'px ' + fontFamily;
@@ -258,7 +280,7 @@
return cc.size(canvasWidth, canvasHeight);
};
proto._calculateSplitedStrings = function(canvasSize) {
proto._calculateSplitedStrings = function() {
var node = this._node;
var ctx = this._labelContext;
@@ -268,7 +290,7 @@
if (node._isWrapText) {
this._splitedStrings = [];
for (i = 0; i < paragraphedStrings.length; ++i) {
this._splitedStrings = this._splitedStrings.concat(this._fragmentText(paragraphedStrings[i], canvasSize.width, ctx));
this._splitedStrings = this._splitedStrings.concat(this._fragmentText(paragraphedStrings[i], this._canvasSize.width, ctx));
}
}
else {
@@ -277,14 +299,15 @@
};
proto._updateLabelDimensions = function(canvasSize, ctx) {
proto._updateLabelDimensions = function() {
var node = this._node;
var paragraphedStrings = node._string.split('\n');
var i;
var ctx = this._labelContext;
if (_ccsg.Label.Overflow.RESIZE_HEIGHT === node._overFlow) {
canvasSize.height = this._splitedStrings.length * this._getLineHeight();
_ccsg.Node.prototype.setContentSize.call(node, canvasSize);
this._canvasSize.height = this._splitedStrings.length * this._getLineHeight();
_ccsg.Node.prototype.setContentSize.call(node, this._canvasSize);
}
else if(_ccsg.Label.Overflow.NONE === node._overFlow) {
this._splitedStrings = paragraphedStrings;
@@ -296,18 +319,17 @@
}
canvasSizeY = this._splitedStrings.length * this._getLineHeight();
canvasSize.width = canvasSizeX;
canvasSize.height = canvasSizeY;
_ccsg.Node.prototype.setContentSize.call(node, canvasSize);
this._canvasSize.width = parseFloat(canvasSizeX.toFixed(2));
this._canvasSize.height = parseFloat(canvasSizeY.toFixed(2));
_ccsg.Node.prototype.setContentSize.call(node, this._canvasSize);
}
this._labelCanvas.width = canvasSize.width;
this._labelCanvas.height = canvasSize.height;
this._labelCanvas.width = this._canvasSize.width;
this._labelCanvas.height = this._canvasSize.height;
this._labelContext.clearRect(0, 0, this._labelCanvas.width, this._labelCanvas.height);
};
proto._calculateFillTextStartPosition = function(canvasSize) {
proto._calculateFillTextStartPosition = function() {
var node = this._node;
var lineHeight = this._getLineHeight();
var lineCount = this._splitedStrings.length;
@@ -315,10 +337,10 @@
var firstLinelabelY;
if (cc.TextAlignment.RIGHT === node._hAlign) {
labelX = canvasSize.width;
labelX = this._canvasSize.width;
}
else if (cc.TextAlignment.CENTER === node._hAlign) {
labelX = canvasSize.width / 2;
labelX = this._canvasSize.width / 2;
}
else {
labelX = 0;
@@ -328,10 +350,10 @@
firstLinelabelY = 0;
}
else if (cc.VerticalTextAlignment.CENTER === node._vAlign) {
firstLinelabelY = canvasSize.height / 2 - lineHeight * (lineCount - 1) / 2;
firstLinelabelY = this._canvasSize.height / 2 - lineHeight * (lineCount - 1) / 2;
}
else {
firstLinelabelY = canvasSize.height - lineHeight * (lineCount - 1);
firstLinelabelY = this._canvasSize.height - lineHeight * (lineCount - 1);
}
return cc.p(labelX, firstLinelabelY);
@@ -369,24 +391,35 @@
var node = this._node;
this._drawFontsize = node._fontSize;
var canvasSize = this._calculateCanvasSize();
this._canvasSize = this._calculateCanvasSize();
//Note: don't change the calling order of the following 3 statements
var fontDesc = this._calculateLabelFont(canvasSize);
this._calculateSplitedStrings(canvasSize);
this._updateLabelDimensions(canvasSize, this._labelContext);
//this._labelContext.fillStyle = "rgb(128,128,128)";
//this._labelContext.fillRect(0,0,this._labelCanvas.width,this._labelCanvas.height);
var color = this._displayedColor;
this._labelContext.fillStyle = 'rgb(' + color.r + ',' + color.g + ',' + color.b + ')';
this._fontDesc = this._calculateLabelFont();
this._calculateSplitedStrings();
this._updateLabelDimensions();
this._calculateTextBaseline();
var startPosition = this._calculateFillTextStartPosition(canvasSize);
this._updateTexture();
};
// proto._updateColor = function() {
// this._rebuildLabelSkin();
// };
proto._updateTexture = function() {
this._labelContext.clearRect(0, 0, this._labelCanvas.width, this._labelCanvas.height);
this._fontDesc = this._calculateLabelFont();
this._labelContext.font = this._fontDesc;
var startPosition = this._calculateFillTextStartPosition();
var lineHeight = this._getLineHeight();
this._labelContext.font = fontDesc;
var color = this._displayedColor;
this._labelContext.fillStyle = 'rgb(' + color.r + ',' + color.g + ',' + color.b + ')';
//do real rendering
for (var i = 0; i < this._splitedStrings.length; ++i) {
this._labelContext.fillText(this._splitedStrings[i], startPosition.x, startPosition.y + i * lineHeight);
@@ -397,18 +430,11 @@
};
proto._rebuildLabelSkin = function () {
this._dirtyFlag = this._dirtyFlag & _ccsg.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
var node = this._node;
if (node._labelSkinDirty) {
if (node._labelType === _ccsg.Label.Type.TTF ||
node._labelType === _ccsg.Label.Type.SystemFont) {
this._bakeLabel();
this._prepareQuad();
}
else {
node._updateContent();
}
this._node._labelSkinDirty = false;
}
this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node);
node._updateLabel();
};
})();
@@ -435,10 +461,7 @@
proto.constructor = _ccsg.Label.CanvasRenderCmd;
proto.rendering = function (ctx, scaleX, scaleY) {
this._rebuildLabelSkin();
var node = this._node;
this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node);
if (node._labelType === _ccsg.Label.Type.TTF ||
node._labelType === _ccsg.Label.Type.SystemFont) {
@@ -60,9 +60,6 @@ proto.constructor = _ccsg.Label.WebGLRenderCmd;
proto.rendering = function (ctx) {
var node = this._node;
this._rebuildLabelSkin();
this._realRenderingSize = _ccsg.Node.prototype.getContentSize.call(node);
if(node._labelType === _ccsg.Label.Type.TTF ||
node._labelType === _ccsg.Label.Type.SystemFont){
+21 -1
View File
@@ -976,6 +976,26 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
return null;
},
/**
* Returns a child from the container given its uuid
* @method getChildByUuid
* @param {String} uuid - The uuid to find the child node.
* @return {Node} a Node whose uuid equals to the input parameter
*/
getChildByUuid: function(uuid){
if(!uuid){
cc.log("Invalid uuid");
return null;
}
var locChildren = this._children;
for(var i = 0, len = locChildren.length; i < len; i++){
if(locChildren[i]._id === uuid)
return locChildren[i];
}
return null;
},
/**
* Returns a child from the container given its name
* @method getChildByName
@@ -1473,7 +1493,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
var sibling = siblings[i];
sibling._sgNode.arrivalOrder = i;
}
if (cc.renderer) {
if ( !CC_JSB ) {
cc.renderer.childrenOrderDirty = this._parent._sgNode._reorderChildDirty = true;
}
this._parent.emit(CHILD_REORDER);
+3 -2
View File
@@ -30,8 +30,9 @@ var SceneGraphUtils = {
var node = this._sgNode;
if (node) {
node.release();
if (node._parent) {
node._parent.removeChild(node);
var parent = node._parent;
if (parent) {
parent.removeChild(node);
}
}
},
+3 -1
View File
@@ -107,7 +107,9 @@ for (var i = 0; i < actionArr.length; ++i) {
continue;
var proto = type.prototype;
setCtorReplacer(proto);
setAliasReplacer(name, type);
if (name.indexOf('Ease') === -1) {
setAliasReplacer(name, type);
}
}
function setChainFuncReplacer (proto, name) {
+14 -6
View File
@@ -96,7 +96,7 @@ cc.js.mixin(cc.director, {
*/
runSceneImmediate: function (scene, onBeforeLoadScene, onLaunched) {
// detach persist nodes
var i, node, game = cc.game;
var id, node, game = cc.game;
var persistNodes = game._persistRootNodes;
// Run an Entity Scene
@@ -105,8 +105,8 @@ cc.js.mixin(cc.director, {
scene._load();
}
for (i = persistNodes.length - 1; i >= 0; --i) {
node = persistNodes[i];
for (id in persistNodes) {
node = persistNodes[id];
game._ignoreRemovePersistNode = node;
node.parent = null;
game._ignoreRemovePersistNode = null;
@@ -134,9 +134,17 @@ cc.js.mixin(cc.director, {
sgScene = scene._sgNode;
// Re-attach persist nodes
for (i = 0; i < persistNodes.length; ++i) {
node = persistNodes[i];
node.parent = scene;
for (id in persistNodes) {
node = persistNodes[id];
var existNode = scene.getChildByUuid(id);
// Scene contains the persist node, should not reattach, should update the persist node
if (existNode) {
persistNodes[id] = existNode;
existNode._persistNode = true;
}
else {
node.parent = scene;
}
}
scene._activate();
}
+7 -2
View File
@@ -70,6 +70,9 @@ cc.js.mixin(cc.path, {
});
// cc.Scheduler
cc.Scheduler.prototype.schedule = function (callback, target, interval, repeat, delay, paused) {
this.scheduleCallbackForTarget(target, callback, interval, repeat, delay, paused);
};
cc.Scheduler.prototype.scheduleUpdate = cc.Scheduler.prototype.scheduleUpdateForTarget;
cc.Scheduler.prototype._unschedule = cc.Scheduler.prototype.unschedule;
cc.Scheduler.prototype.unschedule = function (callback, target) {
@@ -81,8 +84,10 @@ cc.Scheduler.prototype.unschedule = function (callback, target) {
this._unschedule(target, callback);
};
// Node arrivalOrder
cc.defineGetterSetter(cc.Node.prototype, "arrivalOrder", cc.Node.prototype.getOrderOfArrival, cc.Node.prototype.setOrderOfArrival);
// Node
var nodeProto = cc.Node.prototype;
cc.defineGetterSetter(nodeProto, "arrivalOrder", nodeProto.getOrderOfArrival, nodeProto.setOrderOfArrival);
cc.defineGetterSetter(nodeProto, "_parent", nodeProto.getParent, nodeProto.setParent);
// TextureCache addImage
if (!cc.TextureCache.prototype._addImageAsync) {
+11 -9
View File
@@ -34,7 +34,7 @@ cc.js.mixin(cc.game, {
// Scenes list
_sceneInfos: [],
_persistRootNodes: [],
_persistRootNodes: {},
_ignoreRemovePersistNode: null,
CONFIG_KEY: {
@@ -145,10 +145,12 @@ cc.js.mixin(cc.game, {
* @param {ENode} node - The node to be made persistent
*/
addPersistRootNode: function (node) {
if (!(node instanceof cc.Node))
if (!(node instanceof cc.Node) || !node._id) {
cc.warn('The target can not be made persist because it\'s not a cc.Node or it doesn\'t have _id property.');
return;
var index = this._persistRootNodes.indexOf(node);
if (index === -1) {
}
var id = node._id;
if (!this._persistRootNodes[id]) {
var scene = cc.director._scene;
if (cc.isValid(scene)) {
if (!node.parent) {
@@ -162,7 +164,7 @@ cc.js.mixin(cc.game, {
cc.warn('The node can not be made persist because it\'s not in current scene.');
return;
}
this._persistRootNodes.push(node);
this._persistRootNodes[id] = node;
node._persistNode = true;
}
}
@@ -175,11 +177,11 @@ cc.js.mixin(cc.game, {
*/
removePersistRootNode: function (node) {
if (node !== this._ignoreRemovePersistNode) {
var index = this._persistRootNodes.indexOf(node);
if (index !== -1) {
this._persistRootNodes.splice(index, 1);
var id = node._id || '';
if (node === this._persistRootNodes[id]) {
delete this._persistRootNodes[id];
node._persistNode = false;
}
node._persistNode = false;
}
},
+35
View File
@@ -1203,3 +1203,38 @@ test('play Animation', function () {
strictEqual(moveState.isPlaying, false, 'move animation state should not be playing');
strictEqual(rotateState.isPlaying, false, 'rotate animation state should be playing');
});
test('animation enabled/disabled', function () {
var scene = cc.director.getScene();
var entity = new cc.Node();
var animation = entity.addComponent(cc.Animation);
entity.parent = scene;
var clip = new cc.AnimationClip();
clip._name = 'move';
clip._duration = 1;
clip.curveData = {
props: {
x: [
{frame: 0, value: 0},
{frame: 1, value: 100}
]
}
};
animation.addClip(clip);
animation.play('move');
animation.enabled = false;
strictEqual(animation._animator.isPlaying, true, 'move animation should be playing');
strictEqual(animation._animator.isPaused, true, 'move animation should be paused');
animation.enabled = true;
strictEqual(animation._animator.isPlaying, true, 'move animation should be playing');
strictEqual(animation._animator.isPaused, false, 'move animation should be resumed');
entity.parent = null;
});