Merge branch 'master' into refineSprite

This commit is contained in:
Huabing.Xu
2016-01-19 17:02:42 +08:00
33 changed files with 1135 additions and 767 deletions
-110
View File
@@ -1,110 +0,0 @@
var NodeWrapper = require('../node');
var WidgetWrapper = require('./widget');
var LayoutWrapper = cc.Class({
name: 'cc.LayoutWrapper',
extends: WidgetWrapper,
properties: {
clippingEnabled: {
get: function () {
return this.targetN.clippingEnabled;
},
set: function (value) {
if (typeof value === 'boolean') {
this.targetN.clippingEnabled = value;
cc.renderer.childrenOrderDirty = true;
if (CC_EDITOR) {
cc.engine.repaintInEditMode();
}
}
else {
cc.error('The new clippingEnabled must be boolean');
}
}
},
layoutType: {
get: function () {
return this.targetN.layoutType;
},
set: function (value) {
if (typeof value === 'number' && !isNaN(value)) {
this.targetN.layoutType = value;
this.updateChildLayoutType();
this.doLayout();
}
else {
cc.error('The new layoutType must be number');
}
},
type: ccui.Layout.Type
},
_layoutType: {
default: 0
},
_clippingEnabled: {
default: null
}
},
updateChildLayoutType: function () {
var layoutType = this.layoutType;
this.children.forEach( function (child) {
child.widgetLayoutType = layoutType;
});
},
addChildN: function (child) {
var wrapper = cc.getWrapper(child);
wrapper.widgetLayoutType = this.layoutType;
NodeWrapper.prototype.addChildN.call(this, child);
},
canAddChildN: function (child) {
if ( !(child instanceof ccui.Widget) ) {
cc.error('Layout can only add ccui.Widget as a child');
return false;
}
return true;
},
onChildSiblingIndexChanged: function () {
this.doLayout();
},
doLayout: function () {
this.targetN.requestDoLayout();
cc.renderer.childrenOrderDirty = true;
if (CC_EDITOR) {
cc.engine.repaintInEditMode();
}
},
onBeforeSerialize: function () {
WidgetWrapper.prototype.onBeforeSerialize.call(this);
this._layoutType = this.layoutType;
this._clippingEnabled = this.clippingEnabled;
},
createNode: function (node) {
node = node || new ccui.Layout();
WidgetWrapper.prototype.createNode.call(this, node);
node.layoutType = this._layoutType;
if (this._clippingEnabled !== null)
node.clippingEnabled = this._clippingEnabled;
return node;
}
});
cc.LayoutWrapper = module.exports = LayoutWrapper;
@@ -1,99 +0,0 @@
var LayoutWrapper = require('./layout');
var ScrollViewWrapper = cc.Class({
name: 'cc.ScrollViewWrapper',
extends: LayoutWrapper,
properties: {
direction: {
get: function () {
return this.targetN.getDirection();
},
set: function (value) {
if (typeof value === 'number' && !isNaN(value)) {
this.targetN.setDirection(value);
this.doLayout();
}
else {
cc.error('The new direction must be number');
}
},
type: ccui.ScrollView.Dir
},
bounce: {
get: function () {
return this.targetN.isBounceEnabled();
},
set: function (value) {
if (typeof value === 'boolean') {
this.targetN.setBounceEnabled(value);
}
else {
cc.error('The new bounce must be boolean');
}
}
},
innerSize: {
get: function () {
var size = this.targetN.getInnerContainerSize();
return new cc.Vec2(size.width, size.height);
},
set: function (value) {
if ( value instanceof cc.Vec2 ) {
this.targetN.setInnerContainerSize( cc.size(value.x, value.y) );
this.doLayout();
}
else {
cc.error('The new innerSize must be cc.Vec2');
}
}
},
_direction: {
default: ccui.ScrollView.Dir.NONE,
type: ccui.ScrollView.Dir
},
_bounce: {
default: false
},
_innerSize: {
default: null
}
},
doLayout: function () {
this.targetN._innerContainer.requestDoLayout();
LayoutWrapper.prototype.doLayout.call(this);
},
onBeforeSerialize: function () {
LayoutWrapper.prototype.onBeforeSerialize.call(this);
this._direction = this.direction;
this._bounce = this.bounce;
this._innerSize = [this.innerSize.x, this.innerSize.y];
},
createNode: function (node) {
node = node || new ccui.ScrollView();
LayoutWrapper.prototype.createNode.call(this, node);
node.setDirection( this._direction );
node.setBounceEnabled( this._bounce );
var innerSize = this._innerSize;
if (innerSize) node.setInnerContainerSize( cc.size(innerSize[0], innerSize[1]) );
return node;
}
});
cc.ScrollViewWrapper = module.exports = ScrollViewWrapper;
+4 -4
View File
@@ -25,7 +25,7 @@
****************************************************************************/
/**
* @module actions
* @module cc
*/
/** Default Action tag
@@ -234,7 +234,7 @@ cc.FiniteTimeAction = cc.Action.extend({
});
/**
* @module actions
* @module cc
*/
/*
@@ -355,7 +355,7 @@ cc.Speed = cc.Action.extend({
*
* @warning This action can't be Sequenceable because it is not an cc.IntervalAction
*
* @method cc.speed
* @method speed
* @param {ActionInterval} action
* @param {Number} speed
* @return {Speed}
@@ -545,7 +545,7 @@ cc.Follow = cc.Action.extend({
/**
* Create a follow action which makes its target follows another node.
*
* @method
* @method follow
* @param {Node} followedNode
* @param {Rect} rect
* @return {Follow|Null} returns the cc.Follow object on success
+5 -5
View File
@@ -33,7 +33,7 @@
****************************************************************************/
/**
* @module actions
* @module cc
*/
/*
@@ -267,7 +267,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend({
/**
* creates an action with a Cardinal Spline array of points and tension.
*
* @method cc.cardinalSplineTo
* @method cardinalSplineTo
* @param {Number} duration
* @param {Array} points array of control points
* @param {Number} tension
@@ -378,7 +378,7 @@ cc.CardinalSplineBy = cc.CardinalSplineTo.extend({
/**
* creates an action with a Cardinal Spline array of points and tension.
*
* @method cc.cardinalSplineBy
* @method cardinalSplineBy
* @param {Number} duration
* @param {Array} points
* @param {Number} tension
@@ -430,7 +430,7 @@ cc.CatmullRomTo = cc.CardinalSplineTo.extend({
/**
* creates an action with a Cardinal Spline array of points and tension.
*
* @method cc.catmullRomTo
* @method catmullRomTo
* @param {Number} dt
* @param {Array} points
* @return {CatmullRomTo}
@@ -484,7 +484,7 @@ cc.CatmullRomBy = cc.CardinalSplineBy.extend({
/**
* Creates an action with a Cardinal Spline array of points and tension
* @method cc.catmullRomBy
* @method catmullRomBy
* @param {Number} dt
* @param {Array} points
* @return {CatmullRomBy}
+38 -38
View File
@@ -25,7 +25,7 @@
****************************************************************************/
/**
* @module actions
* @module cc
*/
/**
@@ -163,7 +163,7 @@ cc.easeRateAction = function (action, rate) {
cc.EaseRateAction.create = cc.easeRateAction;
/**
* @module actions
* @module cc
*/
/*
@@ -205,7 +205,7 @@ cc.EaseIn.create = function (action, rate) {
* Creates the action easing object with the rate parameter. <br />
* From slow to fast.
*
* @method cc.easeIn
* @method easeIn
* @param {Number} rate
* @return {Object}
* @example
@@ -262,7 +262,7 @@ cc.EaseOut.create = function (action, rate) {
* Creates the action easing object with the rate parameter. <br />
* From fast to slow.
*
* @method cc.easeOut
* @method easeOut
* @param {Number} rate
* @return {Object}
* @example
@@ -322,7 +322,7 @@ cc.EaseInOut.create = function (action, rate) {
/**
* Creates the action easing object with the rate parameter. <br />
* Slow to fast then to slow.
* @method cc.easeInOut
* @method easeInOut
* @param {Number} rate
* @return {Object}
*
@@ -394,7 +394,7 @@ cc._easeExponentialInObj = {
* Creates the action easing object with the rate parameter. <br />
* Reference easeInExpo: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeExponentialIn
* @method easeExponentialIn
* @return {Object}
* @example
* // example
@@ -452,7 +452,7 @@ cc._easeExponentialOutObj = {
* creates the action easing object. <br />
* Reference easeOutExpo: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeExponentialOut
* @method easeExponentialOut
* @return {Object}
* @example
* // example
@@ -525,7 +525,7 @@ cc._easeExponentialInOutObj = {
* creates an EaseExponentialInOut action easing object. <br />
* Reference easeInOutExpo: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeExponentialInOut
* @method easeExponentialInOut
* @return {Object}
* @example
* // example
@@ -583,7 +583,7 @@ cc._easeSineInObj = {
* creates an EaseSineIn action. <br />
* Reference easeInSine: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeSineIn
* @method easeSineIn
* @return {Object}
* @example
* // example
@@ -642,7 +642,7 @@ cc._easeSineOutObj = {
* Creates an EaseSineOut action easing object. <br />
* Reference easeOutSine: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeSineOut
* @method easeSineOut
* @return {Object}
* @example
* // example
@@ -701,7 +701,7 @@ cc._easeSineInOutObj = {
* creates the action easing object. <br />
* Reference easeInOutSine: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeSineInOut
* @method easeSineInOut
* @return {Object}
* @example
* // example
@@ -772,7 +772,7 @@ cc.EaseElastic.create = function (action, period) {
};
/**
* @module actions
* @module cc
*/
/*
@@ -836,7 +836,7 @@ cc._easeElasticInObj = {
* Creates the action easing obejct with the period in radians (default is 0.3). <br />
* Reference easeInElastic: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeElasticIn
* @method easeElasticIn
* @param {Number} [period=0.3]
* @return {Object}
* @example
@@ -918,7 +918,7 @@ cc._easeElasticOutObj = {
* Creates the action easing object with the period in radians (default is 0.3). <br />
* Reference easeOutElastic: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeElasticOut
* @method easeElasticOut
* @param {Number} [period=0.3]
* @return {Object}
* @example
@@ -996,7 +996,7 @@ cc.EaseElasticInOut.create = function (action, period) {
* Creates the action easing object with the period in radians (default is 0.3). <br />
* Reference easeInOutElastic: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeElasticInOut
* @method easeElasticInOut
* @param {Number} [period=0.3]
* @return {Object}
* @example
@@ -1073,7 +1073,7 @@ cc.EaseBounce.create = function (action) {
};
/**
* @module actions
* @module cc
*/
/*
@@ -1139,7 +1139,7 @@ cc._easeBounceInObj = {
/**
* Creates the action easing object. <br />
* Eased bounce effect at the beginning.
* @method cc.easeBounceIn
* @method easeBounceIn
* @return {Object}
* @example
* // example
@@ -1197,7 +1197,7 @@ cc._easeBounceOutObj = {
/**
* Creates the action easing object. <br />
* Eased bounce effect at the ending.
* @method cc.easeBounceOut
* @method easeBounceOut
* @return {Object}
* @example
* // example
@@ -1268,7 +1268,7 @@ cc._easeBounceInOutObj = {
/**
* Creates the action easing object. <br />
* Eased bounce effect at the begining and ending.
* @method cc.easeBounceInOut
* @method easeBounceInOut
* @return {Object}
* @example
* // example
@@ -1328,7 +1328,7 @@ cc._easeBackInObj = {
/**
* Creates the action easing object. <br />
* In the opposite direction to move slowly, and then accelerated to the right direction.
* @method cc.easeBackIn
* @method easeBackIn
* @return {Object}
* @example
* // example
@@ -1389,7 +1389,7 @@ cc._easeBackOutObj = {
/**
* Creates the action easing object. <br />
* Fast moving more than the finish, and then slowly back to the finish.
* @method cc.easeBackOut
* @method easeBackOut
* @return {Object}
* @example
* // example
@@ -1460,7 +1460,7 @@ cc._easeBackInOutObj = {
/**
* Creates the action easing object. <br />
* Begining of cc.EaseBackIn. Ending of cc.EaseBackOut.
* @method cc.easeBackInOut
* @method easeBackInOut
* @return {Object}
* @example
* // example
@@ -1548,7 +1548,7 @@ cc.EaseBezierAction.create = function(action){
* Creates the action easing object. <br />
* Into the 4 reference point. <br />
* To calculate the motion curve.
* @method cc.easeBezierAction
* @method easeBezierAction
* @param {Number} p0 The first bezier parameter
* @param {Number} p1 The second bezier parameter
* @param {Number} p2 The third bezier parameter
@@ -1621,7 +1621,7 @@ cc._easeQuadraticActionIn = {
* Creates the action easing object. <br />
* Reference easeInQuad: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuadraticActionIn
* @method easeQuadraticActionIn
* @returns {Object}
* @example
* //example
@@ -1681,7 +1681,7 @@ cc._easeQuadraticActionOut = {
* Creates the action easing object. <br />
* Reference easeOutQuad: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuadraticActionOut
* @method easeQuadraticActionOut
* @returns {Object}
* @example
* //example
@@ -1749,7 +1749,7 @@ cc._easeQuadraticActionInOut = {
* Creates the action easing object. <br />
* Reference easeInOutQuad: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuadraticActionInOut
* @method easeQuadraticActionInOut
* @returns {Object}
* @example
* //example
@@ -1808,7 +1808,7 @@ cc._easeQuarticActionIn = {
* Creates the action easing object. <br />
* Reference easeIntQuart: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuarticActionIn
* @method easeQuarticActionIn
* @returns {Object}
* @example
* //example
@@ -1869,7 +1869,7 @@ cc._easeQuarticActionOut = {
* Creates the action easing object. <br />
* Reference easeOutQuart: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuarticActionOut
* @method easeQuarticActionOut
* @returns {Object}
* @example
* //example
@@ -1932,7 +1932,7 @@ cc._easeQuarticActionInOut = {
* Creates the action easing object. <br />
* Reference easeInOutQuart: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuarticActionInOut
* @method easeQuarticActionInOut
* @returns {Object}
*/
cc.easeQuarticActionInOut = function(){
@@ -1989,7 +1989,7 @@ cc._easeQuinticActionIn = {
* Creates the action easing object. <br />
* Reference easeInQuint: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuinticActionIn
* @method easeQuinticActionIn
* @returns {Object}
* @example
* //example
@@ -2050,7 +2050,7 @@ cc._easeQuinticActionOut = {
* Creates the action easing object. <br />
* Reference easeOutQuint: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuinticActionOut
* @method easeQuinticActionOut
* @returns {Object}
* @example
* //example
@@ -2114,7 +2114,7 @@ cc._easeQuinticActionInOut = {
* Creates the action easing object. <br />
* Reference easeInOutQuint: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeQuinticActionInOut
* @method easeQuinticActionInOut
* @returns {Object}
* @example
* //example
@@ -2174,7 +2174,7 @@ cc._easeCircleActionIn = {
* Creates the action easing object. <br />
* Reference easeInCirc: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeCircleActionIn
* @method easeCircleActionIn
* @returns {Object}
* @example
* //example
@@ -2235,7 +2235,7 @@ cc._easeCircleActionOut = {
* Creates the action easing object. <br />
* Reference easeOutCirc: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeCircleActionOut
* @method easeCircleActionOut
* @returns {Object}
* @exampple
* //example
@@ -2299,7 +2299,7 @@ cc._easeCircleActionInOut = {
* Creates the action easing object. <br />
* Reference easeInOutCirc: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeCircleActionInOut
* @method easeCircleActionInOut
* @returns {Object}
* @example
* //example
@@ -2359,7 +2359,7 @@ cc._easeCubicActionIn = {
* Creates the action easing object. <br />
* Reference easeInCubic: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeCubicActionIn
* @method easeCubicActionIn
* @returns {Object}
* @example
* //example
@@ -2420,7 +2420,7 @@ cc._easeCubicActionOut = {
* Creates the action easing object. <br />
* Reference easeOutCubic: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeCubicActionOut
* @method easeCubicActionOut
* @returns {Object}
* @example
* //example
@@ -2484,7 +2484,7 @@ cc._easeCubicActionInOut = {
* Creates the action easing object. <br />
* Reference easeInOutCubic: <br />
* http://www.zhihu.com/question/21981571/answer/19925418
* @method cc.easeCubicActionInOut
* @method easeCubicActionInOut
* @returns {Object}
*/
cc.easeCubicActionInOut = function(){
+10 -10
View File
@@ -25,7 +25,7 @@
****************************************************************************/
/**
* @module actions
* @module cc
*/
/**
@@ -63,7 +63,7 @@ cc.ActionInstant = cc.FiniteTimeAction.extend({
});
/**
* @module actions
* @module cc
*/
/*
@@ -88,7 +88,7 @@ cc.Show = cc.ActionInstant.extend({
/**
* Show the Node.
* @method cc.show
* @method show
* @return {Show}
* @example
* // example
@@ -122,7 +122,7 @@ cc.Hide = cc.ActionInstant.extend({
/**
* Hide the node.
* @method cc.hide
* @method hide
* @return {Hide}
* @example
* // example
@@ -156,7 +156,7 @@ cc.ToggleVisibility = cc.ActionInstant.extend({
/**
* Toggles the visibility of a node.
* @method cc.toggleVisibility
* @method toggleVisibility
* @return {ToggleVisibility}
* @example
* // example
@@ -208,7 +208,7 @@ cc.RemoveSelf = cc.ActionInstant.extend({
/**
* Create a RemoveSelf object with a flag indicate whether the target should be cleaned up while removing.
*
* @method cc.removeSelf
* @method removeSelf
* @param {Boolean} [isNeedCleanUp=true]
* @return {RemoveSelf}
*
@@ -268,7 +268,7 @@ cc.FlipX = cc.ActionInstant.extend({
/**
* Create a FlipX action to flip or unflip the target.
*
* @method cc.flipX
* @method flipX
* @param {Boolean} flip Indicate whether the target should be flipped or not
* @return {FlipX}
* @example
@@ -326,7 +326,7 @@ cc.FlipY = cc.ActionInstant.extend({
/**
* Create a FlipY action to flip or unflip the target.
*
* @method cc.flipY
* @method flipY
* @param {Boolean} flip
* @return {FlipY}
* @example
@@ -391,7 +391,7 @@ cc.Place = cc.ActionInstant.extend({
/**
* Creates a Place action with a position.
* @method cc.place
* @method place
* @param {Vec2|Number} pos
* @param {Number} [y]
* @return {Place}
@@ -502,7 +502,7 @@ cc.CallFunc = cc.ActionInstant.extend({
/**
* Creates the action with the callback
* @method cc.callFunc
* @method callFunc
* @param {function} selector
* @param {object|null} [selectorTarget]
* @param {*|null} [data] data for function, it accepts all data types.
+29 -29
View File
@@ -25,7 +25,7 @@
****************************************************************************/
/**
* @module actions
* @module cc
*/
/**
@@ -279,7 +279,7 @@ cc.actionInterval = function (d) {
cc.ActionInterval.create = cc.actionInterval;
/**
* @module actions
* @module cc
*/
/*
@@ -418,7 +418,7 @@ cc.Sequence = cc.ActionInterval.extend({
/**
* Helper constructor to create an array of sequenceable actions
* The created action will run actions sequentially, one after another.
* @method cc.sequence
* @method sequence
* @param {Array|FiniteTimeAction} tempArray
* @return {Sequence}
* @example
@@ -595,7 +595,7 @@ cc.Repeat = cc.ActionInterval.extend({
/**
* Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30)
* @method cc.repeat
* @method repeat
* @param {FiniteTimeAction} action
* @param {Number} times
* @return {Repeat}
@@ -699,7 +699,7 @@ cc.RepeatForever = cc.ActionInterval.extend({
/**
* Create a acton which repeat forever
* @method cc.repeatForever
* @method repeatForever
* @param {FiniteTimeAction} action
* @return {RepeatForever}
* @example
@@ -810,7 +810,7 @@ cc.Spawn = cc.ActionInterval.extend({
/**
* Create a spawn action which runs several actions in parallel.
* @method cc.spawn
* @method spawn
* @param {Array|FiniteTimeAction}tempArray
* @return {FiniteTimeAction}
* @example
@@ -928,7 +928,7 @@ cc.RotateTo = cc.ActionInterval.extend({
/**
* Rotates a Node object to a certain angle by modifying its rotation property. <br/>
* The direction will be decided by the shortest angle.
* @method cc.rotateTo
* @method rotateTo
* @param {Number} duration duration in seconds
* @param {Number} deltaAngleX deltaAngleX in degrees.
* @param {Number} [deltaAngleY] deltaAngleY in degrees.
@@ -1015,7 +1015,7 @@ cc.RotateBy = cc.ActionInterval.extend({
/**
* Rotates a Node object clockwise a number of degrees by modifying its rotation property.
* Relative to its properties to modify.
* @method cc.rotateBy
* @method rotateBy
* @param {Number} duration duration in seconds
* @param {Number} deltaAngleX deltaAngleX in degrees
* @param {Number} [deltaAngleY] deltaAngleY in degrees
@@ -1136,7 +1136,7 @@ cc.MoveBy = cc.ActionInterval.extend({
* x and y are relative to the position of the object. <br/>
* Several MoveBy actions can be concurrently called, and the resulting <br/>
* movement will be the sum of individual movements.
* @method cc.moveBy
* @method moveBy
* @param {Number} duration duration in seconds
* @param {Vec2|Number} deltaPos
* @param {Number} deltaY
@@ -1213,7 +1213,7 @@ cc.MoveTo = cc.MoveBy.extend({
* Moves a Node object to the position x,y. x and y are absolute coordinates by modifying its position property. <br/>
* Several MoveTo actions can be concurrently called, and the resulting <br/>
* movement will be the sum of individual movements.
* @method cc.moveTo
* @method moveTo
* @param {Number} duration duration in seconds
* @param {Vec2} position
* @param {Number} y
@@ -1306,7 +1306,7 @@ cc.SkewTo = cc.ActionInterval.extend({
/**
* Create a action which skews a Node object to given angles by modifying its skewX and skewY properties.
* Changes to the specified value.
* @method cc.skewTo
* @method skewTo
* @param {Number} t time in seconds
* @param {Number} sx
* @param {Number} sy
@@ -1380,7 +1380,7 @@ cc.SkewBy = cc.SkewTo.extend({
/**
* Skews a Node object by skewX and skewY degrees. <br />
* Relative to its property modification.
* @method cc.skewBy
* @method skewBy
* @param {Number} t time in seconds
* @param {Number} sx sx skew in degrees for X axis
* @param {Number} sy sy skew in degrees for Y axis
@@ -1508,7 +1508,7 @@ cc.JumpBy = cc.ActionInterval.extend({
/**
* Moves a Node object simulating a parabolic jump movement by modifying it's position property.
* Relative to its movement.
* @method cc.jumpBy
* @method jumpBy
* @param {Number} duration
* @param {Vec2|Number} position
* @param {Number} [y]
@@ -1590,7 +1590,7 @@ cc.JumpTo = cc.JumpBy.extend({
/**
* Moves a Node object to a parabolic position simulating a jump movement by modifying its position property. <br />
* Jump to the specified location.
* @method cc.jumpTo
* @method jumpTo
* @param {Number} duration
* @param {Vec2|Number} position
* @param {Number} [y]
@@ -1609,7 +1609,7 @@ cc.jumpTo = function (duration, position, y, height, jumps) {
cc.JumpTo.create = cc.jumpTo;
/*
* @method cc.bezierAt
* @method bezierAt
* @param {Number} a
* @param {Number} b
* @param {Number} c
@@ -1736,7 +1736,7 @@ cc.BezierBy = cc.ActionInterval.extend({
/**
* An action that moves the target with a cubic Bezier curve by a certain distance.
* Relative to its movement.
* @method cc.bezierBy
* @method bezierBy
* @param {Number} t time in seconds
* @param {Array} c Array of points
* @return {BezierBy}
@@ -1803,7 +1803,7 @@ cc.BezierTo = cc.BezierBy.extend({
});
/**
* An action that moves the target with a cubic Bezier curve to a destination point.
* @method cc.bezierTo
* @method bezierTo
* @param {Number} t
* @param {Array} c array of points
* @return {BezierTo}
@@ -1888,7 +1888,7 @@ cc.ScaleTo = cc.ActionInterval.extend({
});
/**
* Scales a Node object to a zoom factor by modifying it's scale property.
* @method cc.scaleTo
* @method scaleTo
* @param {Number} duration
* @param {Number} sx scale parameter in X
* @param {Number} [sy] scale parameter in Y, if Null equal to sx
@@ -1936,7 +1936,7 @@ cc.ScaleBy = cc.ScaleTo.extend({
/**
* Scales a Node object a zoom factor by modifying it's scale property.
* Relative to its changes.
* @method cc.scaleBy
* @method scaleBy
* @param {Number} duration duration in seconds
* @param {Number} sx sx scale parameter in X
* @param {Number|Null} [sy=] sy scale parameter in Y, if Null equal to sx
@@ -2019,7 +2019,7 @@ cc.Blink = cc.ActionInterval.extend({
});
/**
* Blinks a Node object by modifying it's visible property.
* @method cc.blink
* @method blink
* @param {Number} duration duration in seconds
* @param blinks blinks in times
* @return {Blink}
@@ -2085,7 +2085,7 @@ cc.FadeTo = cc.ActionInterval.extend({
/**
* Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one.
* @method cc.fadeTo
* @method fadeTo
* @param {Number} duration
* @param {Number} opacity 0-255, 0 is transparent
* @return {FadeTo}
@@ -2138,7 +2138,7 @@ cc.FadeIn = cc.FadeTo.extend({
/**
* Fades In an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 0 to 255.
* @method cc.fadeIn
* @method fadeIn
* @param {Number} duration duration in seconds
* @return {FadeIn}
* @example
@@ -2185,7 +2185,7 @@ cc.FadeOut = cc.FadeTo.extend({
/**
* Fades Out an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from 255 to 0.
* @method cc.fadeOut
* @method fadeOut
* @param {Number} d duration in seconds
* @return {FadeOut}
* @example
@@ -2266,7 +2266,7 @@ cc.TintTo = cc.ActionInterval.extend({
/**
* Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
* @method cc.tintTo
* @method tintTo
* @param {Number} duration
* @param {Number} red 0-255
* @param {Number} green 0-255
@@ -2360,7 +2360,7 @@ cc.TintBy = cc.ActionInterval.extend({
/**
* Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
* Relative to their own color change.
* @method cc.tintBy
* @method tintBy
* @param {Number} duration duration in seconds
* @param {Number} deltaRed
* @param {Number} deltaGreen
@@ -2399,7 +2399,7 @@ cc.DelayTime = cc.ActionInterval.extend({
/**
* Delays the action a certain amount of seconds
* @method cc.delayTime
* @method delayTime
* @param {Number} d duration in seconds
* @return {DelayTime}
* @example
@@ -2482,7 +2482,7 @@ cc.ReverseTime = cc.ActionInterval.extend({
/**
* Executes an action in reverse order, from time=duration to time=0.
* @method cc.reverseTime
* @method reverseTime
* @param {FiniteTimeAction} action
* @return {ReverseTime}
* @example
@@ -2651,7 +2651,7 @@ cc.Animate = cc.ActionInterval.extend({
/**
* create the animate with animation
* @method cc.animate
* @method animate
* @param {SpriteFrameAnimation} animation
* @return {Animate}
* @example
@@ -2739,7 +2739,7 @@ cc.TargetedAction = cc.ActionInterval.extend({
/**
* Create an action with the specified action and forced target
* @method cc.targetedAction
* @method targetedAction
* @param {Node} target
* @param {FiniteTimeAction} action
* @return {TargetedAction}
+1 -1
View File
@@ -64,7 +64,7 @@ cc.g_NumberOfDraws = 0;
* - Scheduled timers & drawing are synchronizes with the refresh rate of the display<br/>
* - Only supports animation intervals of 1/60 1/30 & 1/15<br/>
* </p>
* @class Director
* @class director
*/
cc.Director = Class.extend(/** @lends cc.Director# */{
//Variables
+6
View File
@@ -551,6 +551,12 @@ var Node = cc.Class({
}
}
// check conflict
if (CC_EDITOR && !_Scene.DetectConflict.beforeAddComponent(this, constructor)) {
return null;
}
//
var component = new constructor();
+2 -1
View File
@@ -213,7 +213,8 @@ var Component = cc.Class({
},
set: function (value) {
this._name = value;
}
},
visible: false
},
_id: {
+8 -1
View File
@@ -25,6 +25,8 @@ var ComponentInSG = cc.Class({
onLoad: function () {
var sgNode = this._createSgNode();
this._sgNode = sgNode;
this._initSgNode();
this._appendSgNode(sgNode);
if ( !this.node._sizeProvider ) {
this.node._sizeProvider = sgNode;
@@ -57,6 +59,12 @@ var ComponentInSG = cc.Class({
*/
_createSgNode: null,
/**
* @method _initSgNode
* @private
*/
_initSgNode: null,
_removeSgNode: SceneGraphHelper.removeSgNode,
_appendSgNode: function (sgNode) {
@@ -82,7 +90,6 @@ var ComponentInSG = cc.Class({
// retain immediately
// will be released in SceneGraphHelper.removeSgNode
sgNode.retain();
this._sgNode = sgNode;
}
});
+8 -6
View File
@@ -261,23 +261,25 @@ var Label = cc.Class({
},
_createSgNode: function () {
var sgNode = new _ccsg.Label(this.string, this.file);
return new _ccsg.Label(this.string, this.file);
},
_initSgNode: function () {
var sgNode = this._sgNode;
// TODO
// sgNode.enableRichText = this.enableRichText;
sgNode.setHorizontalAlign( this.horizontalAlign );
sgNode.setVerticalAlign( this.verticalAlign );
sgNode.setFontSize( this.fontSize );
sgNode.setFontSize( this._fontSize );
sgNode.setOverflow( this.overflow );
sgNode.enableWrapText( this.enableWrapText );
sgNode.setLineHeight(this.lineHeight);
sgNode.enableWrapText( this._enableWrapText );
sgNode.setLineHeight(this._lineHeight);
if(!this._useOriginalSize){
sgNode.setContentSize(this.node.getContentSize());
}
sgNode.setColor(this.node.color);
return sgNode;
},
_resized: function () {
+426 -53
View File
@@ -41,6 +41,44 @@ var Type = cc.Enum({
* @property {Number} VERTICAL
*/
VERTICAL: 2,
/**
* @property {Number} GRID
*/
GRID: 3,
});
/**
* Enum for Layout Resize Type
* @enum Layout.ResizeType
*/
var ResizeType = cc.Enum({
/**
* @property {Number} NONE
*/
NONE: 0,
/**
* @property {Number} CONTAINER
*/
CONTAINER: 1,
/**
* @property {Number} CHILDREN
*/
CHILDREN: 2
});
/**
* Enum for Grid Layout start axis direction.
* @enum Layout.AxisDirection
*/
var AxisDirection = cc.Enum({
/**
* @property {Number} HORIZONTAL
*/
HORIZONTAL: 0,
/**
* @property {Number} VERTICAL
*/
VERTICAL: 1,
});
/**
@@ -110,28 +148,64 @@ var Layout = cc.Class({
tooltip: 'i18n:COMPONENT.layout.layout_type'
},
_resize: ResizeType.NONE,
/**
* Whether allow layout to adjust size.
* @property {Boolean} autoResize
* @default true
* @readonly
* The are three resize types for Layout.
* None, resize Container and resize children.
* @property {Layout.ResizeType} resize
* @default ResizeType.NONE
*/
autoResize: {
default: true,
readonly: true,
tooltip: 'i18n:COMPONENT.layout.auto_resize'
resize: {
type: ResizeType,
tooltip: 'i18n:COMPONENT.layout.auto_resize',
get: function() {
return this._resize;
},
set: function(value) {
if (this.layoutType === Type.NONE && value === ResizeType.CHILDREN) {
return;
}
this._doLayoutDirty();
this._resize = value;
}
},
/**
* The margin of layout, it only effect the layout in one direction.
* @property {Number} margin
* The cell size for grid layout.
* @property {cc.Size} cellSize
* @default cc.size(40, 40)
*/
margin: {
cellSize: {
default: cc.size(40, 40),
type: cc.Size,
notify: function() {
this._doLayoutDirty();
}
},
/**
* The start axis for grid layout. If you choose horizontal, then children will layout horizontally at first,
* and then break line on demand. Choose vertical if you want to layout vertically at first .
* @property {Layout.AxisDirection} startAxis
*/
startAxis: {
default: AxisDirection.HORIZONTAL,
type: AxisDirection,
notify: function() {
this._doLayoutDirty();
}
},
/**
* The padding of layout, it only effect the layout in one direction.
* @property {Number} padding
*/
padding: {
default: 0,
notify: function() {
this._doLayoutDirty();
},
tooltip: 'i18n:COMPONENT.layout.margin'
},
/**
@@ -190,7 +264,9 @@ var Layout = cc.Class({
statics: {
Type: Type,
VerticalDirection: VerticalDirection,
HorizontalDirection: HorizontalDirection
HorizontalDirection: HorizontalDirection,
ResizeType: ResizeType,
AxisDirection: AxisDirection,
},
onLoad: function() {
@@ -199,7 +275,7 @@ var Layout = cc.Class({
this.node.on('size-changed', this._resized, this);
this.node.on('anchor-changed', this._doLayoutDirty, this);
this.node.on('child-added', this._childrenAddOrDeleted, this);
this.node.on('child-removed', this._childrenAddOrDeleted, this);;
this.node.on('child-removed', this._childrenAddOrDeleted, this);
this._updateChildrenEventListener();
},
@@ -216,7 +292,7 @@ var Layout = cc.Class({
}.bind(this));
},
_childrenAddOrDeleted: function(event) {
_childrenAddOrDeleted: function() {
this._updateChildrenEventListener();
this._doLayoutDirty();
},
@@ -226,71 +302,242 @@ var Layout = cc.Class({
this._doLayoutDirty();
},
_doLayoutHorizontally: function(layoutAnchor, layoutSize, children) {
var newWidth = 0;
_doLayoutHorizontally: function(baseWidth, rowBreak, fnPositionY, applyChildren) {
var layoutAnchor = this.node.getAnchorPoint();
var children = this.node.children;
var sign = 1;
children.forEach(function(child) {
newWidth += child.width;
});
newWidth += (children.length - 1) * this.spacingX + 2 * this.margin;
this.node.setContentSize(newWidth, layoutSize.height);
var leftBoundaryOfLayout = -layoutAnchor.x * newWidth;
var leftBoundaryOfLayout = -layoutAnchor.x * baseWidth;
if (this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT) {
sign = -1;
leftBoundaryOfLayout = (1 - layoutAnchor.x) * newWidth;
leftBoundaryOfLayout = (1 - layoutAnchor.x) * baseWidth;
}
var nextX = leftBoundaryOfLayout + sign * this.margin - sign * this.spacingX;
var nextX = leftBoundaryOfLayout + sign * this.padding - sign * this.spacingX;
var rowMaxHeight = 0;
var tempMaxHeight = 0;
var secondMaxHeight = 0;
var row = 0;
var containerResizeBoundary;
var maxHeightChildAnchor;
var newChildWidth = this.cellSize.width;
if (this.layoutType !== Type.GRID) {
newChildWidth = (baseWidth - 2 * this.padding - (children.length - 1) * this.spacingX) / children.length;
}
children.forEach(function(child) {
//for resizing children
if (this._resize === ResizeType.CHILDREN) {
child.width = newChildWidth;
if (this.layoutType === Type.GRID) {
child.height = this.cellSize.height;
}
}
var anchorX = child.anchorX;
if (secondMaxHeight > tempMaxHeight) {
tempMaxHeight = secondMaxHeight;
}
if (child.height >= tempMaxHeight) {
secondMaxHeight = tempMaxHeight;
tempMaxHeight = child.height;
maxHeightChildAnchor = child.getAnchorPoint();
}
if (this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT) {
anchorX = 1 - child.anchorX;
}
nextX = nextX + sign * anchorX * child.width + sign * this.spacingX;
var rightBoundaryOfChild = sign * (1 - anchorX) * child.width;
child.setPosition(cc.p(nextX, child.y));
if (rowBreak) {
var rowBreakBoundary = nextX + rightBoundaryOfChild + sign * this.padding;
var leftToRightRowBreak = this.horizontalDirection === HorizontalDirection.LEFT_TO_RIGHT && rowBreakBoundary > (1 - layoutAnchor.x) * baseWidth;
var rightToLeftRowBreak = this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT && rowBreakBoundary < -layoutAnchor.x * baseWidth;
nextX += sign * (1 - anchorX) * child.width;
if (leftToRightRowBreak || rightToLeftRowBreak) {
if (child.height >= tempMaxHeight) {
if (secondMaxHeight === 0) {
secondMaxHeight = tempMaxHeight;
}
rowMaxHeight += secondMaxHeight;
secondMaxHeight = tempMaxHeight;
}
else {
rowMaxHeight += tempMaxHeight;
secondMaxHeight = child.height;
tempMaxHeight = 0;
}
nextX = leftBoundaryOfLayout + sign * (this.padding + anchorX * child.width);
row++;
}
}
var finalPositionY = fnPositionY(child, rowMaxHeight, row);
if(baseWidth > (child.width + 2 * this.padding)) {
if (applyChildren) {
child.setPosition(cc.p(nextX, finalPositionY));
}
}
var signX = 1;
var tempFinalPositionY;
var topMarign = (tempMaxHeight === 0) ? child.height : tempMaxHeight;
if (this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM) {
containerResizeBoundary = containerResizeBoundary || this.node._contentSize.height;
signX = -1;
tempFinalPositionY = finalPositionY + signX * (topMarign * maxHeightChildAnchor.y + this.padding);
if (tempFinalPositionY < containerResizeBoundary) {
containerResizeBoundary = tempFinalPositionY;
}
}
else {
containerResizeBoundary = containerResizeBoundary || -this.node._contentSize.height;
tempFinalPositionY = finalPositionY + signX * (topMarign * maxHeightChildAnchor.y + this.padding);
if (tempFinalPositionY > containerResizeBoundary) {
containerResizeBoundary = tempFinalPositionY;
}
}
nextX += rightBoundaryOfChild;
}.bind(this));
return containerResizeBoundary;
},
_doLayoutVertically: function(layoutAnchor, layoutSize, children) {
_getVerticalBaseHeight: function (children) {
var newHeight = 0;
if (this.resize === ResizeType.CONTAINER) {
children.forEach(function(child) {
newHeight += child.height;
});
newHeight += (children.length - 1) * this.spacingY + 2 * this.padding;
}
else {
newHeight = this.node.getContentSize().height;
}
return newHeight;
},
_doLayoutVertically: function(baseHeight, columnBreak, fnPositionX, applyChildren) {
var layoutAnchor = this.node.getAnchorPoint();
var children = this.node.children;
var sign = 1;
children.forEach(function(child) {
newHeight += child.height;
});
newHeight += (children.length - 1) * this.spacingY + 2 * this.margin;
this.node.setContentSize(layoutSize.width, newHeight);
var bottomBoundaryOfLayout = -layoutAnchor.y * newHeight;
var bottomBoundaryOfLayout = -layoutAnchor.y * baseHeight;
if (this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM) {
sign = -1;
bottomBoundaryOfLayout = (1 - layoutAnchor.y) * newHeight;
bottomBoundaryOfLayout = (1 - layoutAnchor.y) * baseHeight;
}
var nextY = bottomBoundaryOfLayout + sign * this.margin - sign * this.spacingY;
var nextY = bottomBoundaryOfLayout + sign * this.padding - sign * this.spacingY;
var columnMaxWidth = 0;
var tempMaxWidth = 0;
var secondMaxWidth = 0;
var column = 0;
var containerResizeBoundary;
var maxWidthChildAnchor;
var newChildHeight = this.cellSize.height;
if (this.layoutType !== Type.GRID) {
newChildHeight = (baseHeight - 2 * this.padding - (children.length - 1) * this.spacingY) / children.length;
}
children.forEach(function(child) {
//for resizing children
if (this.resize === ResizeType.CHILDREN) {
child.height = newChildHeight;
if (this.layoutType === Type.GRID) {
child.width = this.cellSize.width;
}
}
var anchorY = child.anchorY;
if (secondMaxWidth > tempMaxWidth) {
tempMaxWidth = secondMaxWidth;
}
if (child.width >= tempMaxWidth) {
secondMaxWidth = tempMaxWidth;
tempMaxWidth = child.width;
maxWidthChildAnchor = child.getAnchorPoint();
}
if (this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM) {
anchorY = 1 - child.anchorY;
}
nextY = nextY + sign * anchorY * child.height + sign * this.spacingY;
var topBoundaryOfChild = sign * (1 - anchorY) * child.height;
child.setPosition(cc.p(child.x, nextY));
if (columnBreak) {
var columnBreakBoundary = nextY + topBoundaryOfChild + sign * this.padding;
var bottomToTopColumnBreak = this.verticalDirection === VerticalDirection.BOTTOM_TO_TOP && columnBreakBoundary > (1 - layoutAnchor.y) * baseHeight;
var topToBottomColumnBreak = this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM && columnBreakBoundary < -layoutAnchor.y * baseHeight;
nextY += sign * (1 - anchorY) * child.height;
if (bottomToTopColumnBreak || topToBottomColumnBreak) {
if (child.width >= tempMaxWidth) {
if (secondMaxWidth === 0) {
secondMaxWidth = tempMaxWidth;
}
columnMaxWidth += secondMaxWidth;
secondMaxWidth = tempMaxWidth;
}
else {
columnMaxWidth += tempMaxWidth;
secondMaxWidth = child.width;
tempMaxWidth = 0;
}
nextY = bottomBoundaryOfLayout + sign * (this.padding + anchorY * child.height);
column++;
}
}
var finalPositionX = fnPositionX(child, columnMaxWidth, column);
if (baseHeight > (child.height + 2 * this.padding)) {
if (applyChildren) {
child.setPosition(cc.p(finalPositionX, nextY));
}
}
var signX = 1;
var tempFinalPositionX;
//when the item is the last column break item, the tempMaxWidth will be 0.
var rightMarign = (tempMaxWidth === 0) ? child.width : tempMaxWidth;
if (this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT) {
signX = -1;
containerResizeBoundary = containerResizeBoundary || this.node._contentSize.width;
tempFinalPositionX = finalPositionX + signX * (rightMarign * maxWidthChildAnchor.x + this.padding);
if (tempFinalPositionX < containerResizeBoundary) {
containerResizeBoundary = tempFinalPositionX;
}
}
else {
containerResizeBoundary = containerResizeBoundary || -this.node._contentSize.width;
tempFinalPositionX = finalPositionX + signX * (rightMarign * maxWidthChildAnchor.x + this.padding);
if (tempFinalPositionX > containerResizeBoundary) {
containerResizeBoundary = tempFinalPositionX;
}
}
nextY += topBoundaryOfChild;
}.bind(this));
return containerResizeBoundary;
},
_doLayoutBasic: function(layoutAnchor, layoutSize, children) {
_doLayoutBasic: function() {
var children = this.node.children;
var allChildrenBoundingBox = null;
children.forEach(function(child){
@@ -301,7 +548,7 @@ var Layout = cc.Class({
}
});
if(allChildrenBoundingBox) {
if (allChildrenBoundingBox) {
var leftBottomInParentSpace = this.node.parent.convertToNodeSpaceAR(cc.p(allChildrenBoundingBox.x, allChildrenBoundingBox.y));
var rightTopInParentSpace = this.node.parent.convertToNodeSpaceAR(cc.p(allChildrenBoundingBox.x + allChildrenBoundingBox.width,
allChildrenBoundingBox.y + allChildrenBoundingBox.height));
@@ -318,17 +565,143 @@ var Layout = cc.Class({
}
},
_doLayout: function() {
var children = this.node.children;
_doLayoutGridAxisHorizontal: function (layoutAnchor, layoutSize) {
var baseWidth = layoutSize.width;
var sign = 1;
var bottomBoundaryOfLayout = -layoutAnchor.y * layoutSize.height;
if (this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM) {
sign = -1;
bottomBoundaryOfLayout = (1 - layoutAnchor.y) * layoutSize.height;
}
var fnPositionY = function(child, topOffset, row) {
return bottomBoundaryOfLayout + sign * (topOffset + child.anchorY * child.height + this.padding + row * this.spacingY);
}.bind(this);
var newHeight = 0;
if (this.resize === ResizeType.CONTAINER) {
//calculate the new height of container, it won't change the position of it's children
var boundary = this._doLayoutHorizontally(baseWidth, true, fnPositionY, false);
newHeight = bottomBoundaryOfLayout - boundary;
if (newHeight < 0) {
newHeight *= -1;
}
bottomBoundaryOfLayout = -layoutAnchor.y * newHeight;
if (this.verticalDirection === VerticalDirection.TOP_TO_BOTTOM) {
sign = -1;
bottomBoundaryOfLayout = (1 - layoutAnchor.y) * newHeight;
}
}
this._doLayoutHorizontally(baseWidth, true, fnPositionY, true);
if (this.resize === ResizeType.CONTAINER) {
this.node.setContentSize(baseWidth, newHeight);
}
},
_doLayoutGridAxisVertical: function (layoutAnchor, layoutSize) {
var baseHeight = layoutSize.height;
var sign = 1;
var leftBoundaryOfLayout = -layoutAnchor.x * layoutSize.width;
if (this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT) {
sign = -1;
leftBoundaryOfLayout = (1 - layoutAnchor.x) * layoutSize.width;
}
var fnPositionX = function(child, leftOffset, column) {
return leftBoundaryOfLayout + sign * (leftOffset + child.anchorX * child.width + this.padding + column * this.spacingX);
}.bind(this);
var newWidth = 0;
if (this.resize === ResizeType.CONTAINER) {
var boundary = this._doLayoutVertically(baseHeight, true, fnPositionX, false);
newWidth = leftBoundaryOfLayout - boundary;
if (newWidth < 0) {
newWidth *= -1;
}
leftBoundaryOfLayout = -layoutAnchor.x * newWidth;
if (this.horizontalDirection === HorizontalDirection.RIGHT_TO_LEFT) {
sign = -1;
leftBoundaryOfLayout = (1 - layoutAnchor.x) * newWidth;
}
}
this._doLayoutVertically(baseHeight, true, fnPositionX, true);
if (this.resize === ResizeType.CONTAINER) {
this.node.setContentSize(newWidth, baseHeight);
}
},
_doLayoutGrid: function() {
var layoutAnchor = this.node.getAnchorPoint();
var layoutSize = this.node.getContentSize();
if (this.startAxis === AxisDirection.HORIZONTAL) {
this._doLayoutGridAxisHorizontal(layoutAnchor, layoutSize);
}
else if(this.startAxis === AxisDirection.VERTICAL) {
this._doLayoutGridAxisVertical(layoutAnchor, layoutSize);
}
},
_getHorizontalBaseWidth: function (children) {
var newWidth = 0;
if (this.resize === ResizeType.CONTAINER) {
children.forEach(function(child) {
newWidth += child.width;
});
newWidth += (children.length - 1) * this.spacingX + 2 * this.padding;
}
else {
newWidth = this.node.getContentSize().width;
}
return newWidth;
},
_doLayout: function() {
if (this.layoutType === Type.HORIZONTAL) {
this._doLayoutHorizontally(layoutAnchor, layoutSize, children);
} else if (this.layoutType === Type.VERTICAL) {
this._doLayoutVertically(layoutAnchor, layoutSize, children);
} else if (this.layoutType === Type.NONE) {
this._doLayoutBasic(layoutAnchor, layoutSize, children);
var newWidth = this._getHorizontalBaseWidth(this.node.children);
var fnPositionY = function(child) {
return child.y;
};
this._doLayoutHorizontally( newWidth, false, fnPositionY, true);
this.node.width = newWidth;
}
else if (this.layoutType === Type.VERTICAL) {
var newHeight = this._getVerticalBaseHeight(this.node.children);
var fnPositionX = function(child) {
return child.x;
};
this._doLayoutVertically(newHeight, false, fnPositionX, true);
this.node.height = newHeight;
}
else if (this.layoutType === Type.NONE) {
if (this.resize === ResizeType.CONTAINER) {
this._doLayoutBasic();
}
}
else if(this.layoutType === Type.GRID) {
this._doLayoutGrid();
}
},
+2 -2
View File
@@ -58,8 +58,8 @@ var Mask = cc.Class({
onDestroy: function () {
if (cc.sys.isNative) {
this._clippingStencil.release();
this._clippingNode.release();
this._clippingStencil && this._clippingStencil.release();
this._clippingNode && this._clippingNode.release();
}
},
+124 -41
View File
@@ -23,7 +23,23 @@
****************************************************************************/
var SpriteType = cc.SpriteType;
/**
* Sprite Size can track trimmed size, raw size or none
*/
var SizeMode = cc.Enum({
/**
* @property {Number} CUSTOM
*/
CUSTOM: 0,
/**
* @property {Number} TRIMMED
*/
TRIMMED: 1,
/**
* @property {Number} RAW
*/
RAW: 2
});
/**
* Renders a sprite in the scene.
* @class Sprite
@@ -44,8 +60,10 @@ var Sprite = cc.Class({
type: cc.SpriteFrame
},
_type: SpriteType.SIMPLE,
//FIXME:_useOriginalSize is deprecated, since v0.8, it need to be deleted
_useOriginalSize: true,
_sizeMode: -1,
_isTrimmedMode: true,
/**
* The Sprite Atlas.
* @property _atlas
@@ -72,7 +90,7 @@ var Sprite = cc.Class({
var lastSprite = this._spriteFrame;
this._spriteFrame = value;
if (this._sgNode) {
this._applySpriteFrame(this._sgNode, lastSprite);
this._applySpriteFrame(lastSprite);
// color cleared after reset texture, should reapply color
this._sgNode.setColor(this.node._color);
this._sgNode.setOpacity(this.node._opacity);
@@ -99,7 +117,24 @@ var Sprite = cc.Class({
type: SpriteType,
tooltip: 'i18n:COMPONENT.sprite.type',
},
/**
* specify the rendering mode
* @property isTrimmedMode
* @type {Boolean}
*/
isTrimmedMode: {
get: function () {
return this._isTrimmedMode;
},
set: function (value) {
if (this._isTrimmedMode !== value) {
this._isTrimmedMode = value;
this._sgNode.enableTrimmedContentSize(value);
}
}
},
//FIXME:_useOriginalSize is deprecated, since v0.8, it need to be deleted
useOriginalSize: {
get: function () {
return this._useOriginalSize;
@@ -112,7 +147,23 @@ var Sprite = cc.Class({
},
tooltip: 'i18n:COMPONENT.sprite.original_size',
},
/**
* specify the size tracing mode
* @property sizeMode
* @type {SizeMode}
*/
sizeMode: {
get: function () {
return this._sizeMode;
},
set: function (value) {
this._sizeMode = value;
if (value !== SizeMode.CUSTOM) {
this._applySpriteSize();
}
},
type: SizeMode
},
/**
* Only for editor to calculate bounding box.
*/
@@ -145,7 +196,7 @@ var Sprite = cc.Class({
* @method setScale9Enabled
* @param {Boolean} enabled - True to enable 9-slice, false otherwise.
*/
setScale9Enabled: function(enabled) {
setScale9Enabled: function (enabled) {
this.type = enabled ? cc.SpriteType.SLICED : cc.SpriteType.SIMPLE;
},
@@ -154,7 +205,7 @@ var Sprite = cc.Class({
* @method isScale9Enabled
* @return {Boolean} True if 9-slice is enabled, false otherwise.
*/
isScale9Enabled: function(){
isScale9Enabled: function () {
return this.type === cc.SpriteType.SLICED;
},
@@ -224,7 +275,7 @@ var Sprite = cc.Class({
* @method setInsetLeft
* @param {Number} leftInset - The values to use for the cap inset.
*/
setInsetLeft: function(insetLeft){
setInsetLeft: function (insetLeft) {
this._sgNode.setInsetLeft(insetLeft);
},
@@ -233,7 +284,7 @@ var Sprite = cc.Class({
* @method getInsetLeft
* @return {Number} The left sprite's cap inset.
*/
getInsetLeft: function(){
getInsetLeft: function () {
return this._sgNode.getInsetLeft();
},
@@ -242,7 +293,7 @@ var Sprite = cc.Class({
* @method setInsetTop
* @param {Number} topInset - The values to use for the cap inset.
*/
setInsetTop: function(insetTop){
setInsetTop: function (insetTop) {
this._sgNode.setInsetTop(insetTop);
},
@@ -251,7 +302,7 @@ var Sprite = cc.Class({
* @method getInsetTop
* @return {Number} The top sprite's cap inset.
*/
getInsetTop: function(){
getInsetTop: function () {
return this._sgNode.getInsetTop();
},
@@ -260,7 +311,7 @@ var Sprite = cc.Class({
* @method setInsetRight
* @param {Number} rightInset - The values to use for the cap inset.
*/
setInsetRight: function(insetRight){
setInsetRight: function (insetRight) {
this._sgNode.setInsetRight(insetRight);
},
@@ -269,7 +320,7 @@ var Sprite = cc.Class({
* @method getInsetRight
* @return {Number} The right sprite's cap inset.
*/
getInsetRight: function(){
getInsetRight: function () {
return this._sgNode.getInsetRight();
},
@@ -278,7 +329,7 @@ var Sprite = cc.Class({
* @method setInsetBottom
* @param {Number} bottomInset - The values to use for the cap inset.
*/
setInsetBottom: function(insetBottom) {
setInsetBottom: function (insetBottom) {
this._sgNode.setInsetBottom(insetBottom);
},
@@ -287,12 +338,22 @@ var Sprite = cc.Class({
* @method getInsetBottom
* @return {Number} The bottom sprite's cap inset.
*/
getInsetBottom: function(){
getInsetBottom: function () {
return this._sgNode.getInsetBottom();
},
onLoad: function () {
this._super();
//do processing
if (-1 === this._sizeMode) {
//FIXME:_useOriginalSize is deprecated, since v0.8, it need to be deleted
if (this._useOriginalSize) {
this._sizeMode = SizeMode.TRIMMED;
} else {
this._sizeMode = SizeMode.CUSTOM;
}
this._isTrimmedMode = true;
}
this.node.on('size-changed', this._resized, this);
},
@@ -301,11 +362,11 @@ var Sprite = cc.Class({
this.node.off('size-changed', this._resized, this);
},
_applyAtlas: CC_EDITOR && function ( spriteFrame ) {
_applyAtlas: CC_EDITOR && function (spriteFrame) {
// Set atlas
if (spriteFrame && spriteFrame._atlasUuid) {
var self = this;
cc.AssetLibrary.loadAsset(spriteFrame._atlasUuid, function(err, asset) {
cc.AssetLibrary.loadAsset(spriteFrame._atlasUuid, function (err, asset) {
self._atlas = asset;
});
} else {
@@ -313,9 +374,9 @@ var Sprite = cc.Class({
}
},
_applyCapInset: function (sgNode) {
_applyCapInset: function () {
if (this._type === SpriteType.SLICED && this._spriteFrame) {
sgNode = sgNode || this._sgNode;
var sgNode = this._sgNode;
sgNode.setInsetTop(this._spriteFrame.insetTop);
sgNode.setInsetBottom(this._spriteFrame.insetBottom);
sgNode.setInsetRight(this._spriteFrame.insetRight);
@@ -323,36 +384,40 @@ var Sprite = cc.Class({
}
},
_applySpriteSize: function (sgNode) {
sgNode = sgNode || this._sgNode;
if (this._useOriginalSize && this._spriteFrame) {
_applySpriteSize: function () {
if (SizeMode.CUSTOM === this._sizeMode || !this._spriteFrame) {
this.node.setContentSize(this.node.getContentSize(true));
} else if (SizeMode.RAW === this._sizeMode) {
var size = this._spriteFrame.getOriginalSize();
this.node.setContentSize(size);
} else if (SizeMode.TRIMMED === this._sizeMode) {
var rect = this._spriteFrame.getRect();
this.node.setContentSize(cc.size(rect.width, rect.height));
}
else {
} else {
this.node.setContentSize(this.node.getContentSize(true));
}
},
_onSpriteFrameLoaded: function (event, sgNode) {
_onSpriteFrameLoaded: function (event) {
var self = this;
sgNode = sgNode || this._sgNode;
var sgNode = this._sgNode;
sgNode.setSpriteFrame(self._spriteFrame);
self._applyCapInset(sgNode);
self._applyCapInset();
self._applySpriteSize();
if ( this.enabledInHierarchy && !sgNode.isVisible() ) {
if (this.enabledInHierarchy && !sgNode.isVisible()) {
sgNode.setVisible(true);
}
},
_applySpriteFrame: function (sgNode, oldFrame) {
_applySpriteFrame: function (oldFrame) {
var sgNode = this._sgNode;
if (oldFrame && oldFrame.off) {
oldFrame.off('load', this._onSpriteFrameLoaded, this);
}
if (this._spriteFrame) {
if (this._spriteFrame.textureLoaded()) {
this._onSpriteFrameLoaded(null, sgNode);
this._onSpriteFrameLoaded(null);
}
else {
this._spriteFrame.once('load', this._onSpriteFrameLoaded, this);
@@ -369,28 +434,46 @@ var Sprite = cc.Class({
},
_createSgNode: function () {
var sgNode = new cc.Scale9Sprite();
return new cc.Scale9Sprite();
},
this._applySpriteFrame(sgNode, null);
_initSgNode: function () {
var sgNode = this._sgNode;
if (!this.enabledInHierarchy) {
sgNode.setVisible(false);
}
this._applySpriteFrame(null);
// should keep the size of the sg node the same as entity,
// otherwise setContentSize may not take effect
sgNode.setContentSize(this.node.getContentSize(true));
this._applySpriteSize(sgNode);
sgNode.setRenderingType(this._type);
this._applySpriteSize();
return sgNode;
sgNode.setRenderingType(this._type);
},
_resized: function () {
if (this._useOriginalSize && this._spriteFrame) {
var rect = this._spriteFrame.getRect();
var expectedW = rect.width;
var expectedH = rect.height;
if (this._spriteFrame) {
var actualSize = this.node.getContentSize();
var expectedW = actualSize.width;
var expectedH = actualSize.height;
if (this._sizeMode === SizeMode.RAW) {
var size = this._spriteFrame.getOriginalSize();
expectedW = size.width;
expectedH = size.height;
} else if (this._sizeMode === SizeMode.TRIMMED) {
var rect = this._spriteFrame.getRect();
expectedW = rect.width;
expectedH = rect.height;
} else {
}
if (expectedW !== actualSize.width || expectedH !== actualSize.height) {
this.useOriginalSize = false;
this._sizeMode = SizeMode.CUSTOM;
}
}
},
@@ -399,7 +482,7 @@ var Sprite = cc.Class({
var misc = require('../utils/misc');
var SameNameGetSets = ['atlas', 'capInsets', 'insetLeft', 'insetTop', 'insetRight', 'insetBottom'];
var DiffNameGetSets = {
type: [ null, 'setRenderingType']
type: [null, 'setRenderingType']
};
misc.propertyDefine(Sprite, SameNameGetSets, DiffNameGetSets);
+50 -47
View File
@@ -29,12 +29,12 @@
http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
http://www.angelcode.com/products/bmfont/ (Free, Windows only)
****************************************************************************/
(function() {
_ccsg.Label.TTFLabelBaker = function() {
(function () {
_ccsg.Label.TTFLabelBaker = function () {
};
var proto = _ccsg.Label.TTFLabelBaker.prototype = Object.create(Object.prototype);
proto._getLineHeight = function() {
proto._getLineHeight = function () {
//todo refine it
var nodeSpacingY = this._node.getLineHeight();
if (nodeSpacingY === 0) {
@@ -45,7 +45,7 @@
return nodeSpacingY | 0;
};
proto._prepareQuad = function() {
proto._prepareQuad = function () {
var quad = this._quad;
var white = cc.color(255, 255, 255, this._displayedOpacity);
var width = this._node._contentSize.width;
@@ -82,9 +82,14 @@
//check the first character
var wrappedWords = [];
//fast return if strArr is empty
if(strArr.length === 0) {
wrappedWords.push("");
return wrappedWords;
}
var text = strArr;
var allWidth = ctx.measureText(text).width;
while(allWidth > maxWidth && text.length > 1){
while (allWidth > maxWidth && text.length > 1) {
var fuzzyLen = text.length * ( maxWidth / allWidth ) | 0;
var tmpText = text.substr(fuzzyLen);
@@ -151,14 +156,14 @@
text = sLine || tmpText;
allWidth = ctx.measureText(text).width;
}
if(text.length > 0) {
if (text.length > 0) {
wrappedWords.push(text);
}
return wrappedWords;
};
proto._updateDisplayOpacity = function(parentOpacity) {
proto._updateDisplayOpacity = function (parentOpacity) {
_ccsg.Node.RenderCmd.prototype._updateDisplayOpacity.call(this, parentOpacity);
//specify opacity to quad
var color = cc.color(255, 255, 255, this._displayedOpacity);
@@ -169,14 +174,14 @@
quad._tr.colors = color;
this._quadDirty = true;
};
proto._updateDisplayColor = function (parentColor) {
_ccsg.Node.RenderCmd.prototype._updateDisplayColor.call(this, parentColor);
var node = this._node;
node._labelSkinDirty = true;
};
proto._bakeLabel = function() {
proto._bakeLabel = function () {
var node = this._node;
this._drawFontsize = node._fontSize;
var ctx = this._labelContext;
@@ -220,7 +225,7 @@
canvasSizeY = this._splitedStrings.length * this._getLineHeight();
node._setDimensions(cc.size(canvasSizeX, canvasSizeY));
}
} else if(_ccsg.Label.Overflow.SHRINK === node._overFlow) {
} else if (_ccsg.Label.Overflow.SHRINK === node._overFlow) {
this._splitedStrings = paragraphedStrings;
//shrink
if (node._isWrapText) {
@@ -325,14 +330,14 @@
this._labelTexture.handleLoadedTexture();
};
proto._rebuildLabelSkin = function() {
proto._rebuildLabelSkin = function () {
var node = this._node;
if (node._labelSkinDirty) {
if(node._labelType === _ccsg.Label.Type.TTF ||
node._labelType === _ccsg.Label.Type.SystemFont){
if (node._labelType === _ccsg.Label.Type.TTF ||
node._labelType === _ccsg.Label.Type.SystemFont) {
this._bakeLabel();
this._prepareQuad();
}else {
} else {
node._updateContent();
}
this._node._labelSkinDirty = false;
@@ -340,8 +345,8 @@
};
})();
(function() {
_ccsg.Label.CanvasRenderCmd = function(renderableObject) {
(function () {
_ccsg.Label.CanvasRenderCmd = function (renderableObject) {
_ccsg.Node.CanvasRenderCmd.call(this, renderableObject);
this._needDraw = true;
this._labelTexture = new cc.Texture2D();
@@ -361,13 +366,13 @@
proto.constructor = _ccsg.Label.CanvasRenderCmd;
proto.rendering = function(ctx, scaleX, scaleY) {
proto.rendering = function (ctx, scaleX, scaleY) {
this._rebuildLabelSkin();
var node = this._node;
if (node._labelType === _ccsg.Label.Type.TTF ||
node._labelType === _ccsg.Label.Type.SystemFont) {
node._labelType === _ccsg.Label.Type.SystemFont) {
var locDisplayOpacity = this._displayedOpacity;
var alpha = locDisplayOpacity / 255;
//var locTexture = this._labelTexture;
@@ -381,41 +386,39 @@
wrapper.setGlobalAlpha(alpha);
if (this._labelTexture) {
var sx, sy, sw, sh;
var x, y, w, h;
var quad = this._quad; {
var sx, sy, sw, sh;
var x, y, w, h;
x = 0;
y = -this._node._contentSize.height;
w = this._node._contentSize.width;
h = this._node._contentSize.height;
x = quad._bl.vertices.x;
y = quad._bl.vertices.y;
w = quad._tr.vertices.x - quad._bl.vertices.x;
h = quad._tr.vertices.y - quad._bl.vertices.y;
y = -y - h;
var textureWidth = this._labelTexture.getPixelWidth();
var textureHeight = this._labelTexture.getPixelHeight();
var textureWidth = this._labelTexture.getPixelWidth();
var textureHeight = this._labelTexture.getPixelHeight();
sx = quad._bl.texCoords.u * textureWidth;
sy = quad._bl.texCoords.v * textureHeight;
sw = (quad._tr.texCoords.u - quad._bl.texCoords.u) * textureWidth;
sh = (quad._tr.texCoords.v - quad._bl.texCoords.v) * textureHeight;
sx = 0;
sy = 0;
sw = textureWidth;
sh = textureHeight;
x = x * scaleX;
y = y * scaleY;
w = w * scaleX;
h = h * scaleY;
x = x * scaleX;
y = y * scaleY;
w = w * scaleX;
h = h * scaleY;
var image = this._labelTexture._htmlElementObj;
if (this._labelTexture._pattern !== "") {
wrapper.setFillStyle(context.createPattern(image, this._labelTexture._pattern));
context.fillRect(x, y, w, h);
} else {
var image = this._labelTexture._htmlElementObj;
if (this._labelTexture._pattern !== "") {
wrapper.setFillStyle(context.createPattern(image, this._labelTexture._pattern));
context.fillRect(x, y, w, h);
} else {
if(sw !== 0 && sh !== 0 && w !== 0 && h !== 0) {
context.drawImage(image,
sx, sy, sw, sh,
x, y, w, h);
sx, sy, sw, sh,
x, y, w, h);
}
}
}
cc.g_NumberOfDraws = cc.g_NumberOfDraws + 1;
}
+212 -221
View File
@@ -45,11 +45,55 @@ var TYPO_TO_CORRECT = CC_DEV && {
var INVALID_STATICS = CC_DEV && ['name', '__ctors__', '__props__', 'arguments', 'call', 'apply', 'caller',
'length', 'prototype'];
var deferredInitializer = {
// Configs for classes which needs deferred initialization
datas: null,
// register new class
// data - {cls: cls, cb: properties, mixins: options.mixins}
push: function (data) {
if (this.datas) {
this.datas.push(data);
}
else {
this.datas = [data];
// start a new timer to initialize
var self = this;
setTimeout(function () {
self.init();
}, 0);
}
},
init: function () {
var datas = this.datas;
if (datas) {
for (var i = 0; i < datas.length; ++i) {
var data = datas[i];
var cls = data.cls;
var properties = data.props;
if (typeof properties === 'function') {
properties = properties();
}
var name = JS.getClassName(cls);
if (properties) {
declareProperties(cls, name, properties, cls.$super, data.mixins);
}
else {
cc.error('Properties function of "%s" should return an object!', name);
}
}
this.datas = null;
}
}
};
///**
// * both getter and prop must register the name into __props__ array
// * @param {String} name - prop name
// */
var _appendProp = function (cls, name/*, isGetter*/) {
function appendProp (cls, name/*, isGetter*/) {
if (CC_DEV) {
//var JsVarReg = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
//if (!JsVarReg.test(name)) {
@@ -66,127 +110,118 @@ var _appendProp = function (cls, name/*, isGetter*/) {
if (index < 0) {
cls.__props__.push(name);
}
};
}
var _metaClass = {
prop: function (name, defaultValue, attribute) {
'use strict';
if (CC_DEV) {
// check default object value
if (typeof defaultValue === 'object' && defaultValue) {
if (Array.isArray(defaultValue)) {
// check array empty
if (defaultValue.length > 0) {
cc.error('Default array must be empty, set default value of %s.%s to [], ' +
'and initialize in "onLoad" or "ctor" please. (just like "this.%s = [...];")',
JS.getClassName(this), name, name);
return this;
}
}
else if (!_isPlainEmptyObj_DEV(defaultValue)) {
// check cloneable
if (!_cloneable_DEV(defaultValue)) {
cc.error('Do not set default value to non-empty object, ' +
'unless the object defines its own "clone" function. Set default value of %s.%s to null or {}, ' +
'and initialize in "onLoad" or "ctor" please. (just like "this.%s = {foo: bar};")',
JS.getClassName(this), name, name);
return this;
}
function defineProp (cls, className, propName, defaultValue, attrs) {
if (CC_DEV) {
// check default object value
if (typeof defaultValue === 'object' && defaultValue) {
if (Array.isArray(defaultValue)) {
// check array empty
if (defaultValue.length > 0) {
cc.error('Default array must be empty, set default value of %s.%s to [], ' +
'and initialize in "onLoad" or "ctor" please. (just like "this.%s = [...];")',
className, propName, propName);
return;
}
}
// check base prototype to avoid name collision
for (var base = this.$super; base; base = base.$super) {
// 这个循环只能检测到最上面的FireClass的父类,如果再上还有父类,将不做检测。
if (base.prototype.hasOwnProperty(name)) {
cc.error('Can not declare %s.%s, it is already defined in the prototype of %s',
JS.getClassName(this), name, JS.getClassName(base));
else if (!_isPlainEmptyObj_DEV(defaultValue)) {
// check cloneable
if (!_cloneable_DEV(defaultValue)) {
cc.error('Do not set default value to non-empty object, ' +
'unless the object defines its own "clone" function. Set default value of %s.%s to null or {}, ' +
'and initialize in "onLoad" or "ctor" please. (just like "this.%s = {foo: bar};")',
className, propName, propName);
return;
}
}
}
// set default value
Attr.attr(this, name, { 'default': defaultValue });
_appendProp(this, name);
// apply attributes
if (attribute) {
var onAfterProp = null;
var AttrArgStart = 2;
for (var i = AttrArgStart; i < arguments.length; i++) {
var attr = arguments[i];
Attr.attr(this, name, attr);
// register callback
if (attr._onAfterProp) {
onAfterProp = onAfterProp || [];
onAfterProp.push(attr._onAfterProp);
}
}
// call callback
if (onAfterProp) {
for (var c = 0; c < onAfterProp.length; c++) {
onAfterProp[c](this, name);
}
// check base prototype to avoid name collision
for (var base = cls.$super; base; base = base.$super) {
// 这个循环只能检测到最上面的FireClass的父类,如果再上还有父类,将不做检测。
if (base.prototype.hasOwnProperty(propName)) {
cc.error('Can not declare %s.%s, it is already defined in the prototype of %s',
className, propName, className);
return;
}
}
return this;
},
}
get: function (name, getter, attribute) {
'use strict';
// set default value
Attr.attr(cls, propName, { 'default': defaultValue });
if (CC_DEV) {
var d = Object.getOwnPropertyDescriptor(this.prototype, name);
if (d && d.get) {
cc.error('%s: the getter of "%s" is already defined!', JS.getClassName(this), name);
return this;
appendProp(cls, propName);
// apply attributes
if (attrs) {
var onAfterProp = null;
for (var i = 0; i < attrs.length; i++) {
var attr = attrs[i];
Attr.attr(cls, propName, attr);
// register callback
if (attr._onAfterProp) {
onAfterProp = onAfterProp || [];
onAfterProp.push(attr._onAfterProp);
}
}
// call callback
if (onAfterProp) {
for (var c = 0; c < onAfterProp.length; c++) {
onAfterProp[c](cls, propName);
}
}
}
}
if (attribute) {
var AttrArgStart = 2;
for (var i = AttrArgStart; i < arguments.length; i++) {
var attr = arguments[i];
if (CC_DEV) {
if (attr._canUsedInGetter === false) {
cc.error('Can not apply the specified attribute to the getter of "%s.%s", attribute index: %s',
JS.getClassName(this), name, (i - AttrArgStart));
continue;
}
function defineGetSet (cls, name, propName, val, attrs) {
var getter = val.get;
var setter = val.set;
var proto = cls.prototype;
var d = Object.getOwnPropertyDescriptor(proto, propName);
if (getter) {
if (d && d.get && CC_DEV) {
cc.error('"%s": the getter of "%s" is already defined!', name, propName);
return;
}
if (attrs) {
for (var i = 0; i < attrs.length; ++i) {
var attr = attrs[i];
if (attr._canUsedInGetter === false && CC_DEV) {
cc.error('Can not apply the specified attribute to the getter of "%s.%s", ' +
'attribute index: %s', name, propName, i);
continue;
}
Attr.attr(this, name, attr);
Attr.attr(cls, propName, attr);
if (CC_DEV) {
// check attributes
if (attr.serializable === false || attr.editorOnly === true) {
cc.warn('No need to use "serializable: false" or "editorOnly: true" for the getter of %s.%s, ' +
'every getter is actually non-serialized.',
JS.getClassName(this), name);
}
// check attributes
if ((attr.serializable === false || attr.editorOnly === true) && CC_DEV) {
cc.warn('No need to use "serializable: false" or "editorOnly: true" for ' +
'the getter of "%s.%s", every getter is actually non-serialized.',
name, propName);
}
}
}
var forceSerializable = false;
if ( !forceSerializable ) {
Attr.attr(this, name, Attr.NonSerialized);
var ForceSerializable = false;
if (!ForceSerializable) {
Attr.attr(cls, propName, Attr.NonSerialized);
}
if (forceSerializable || CC_DEV) {
if (ForceSerializable || CC_DEV) {
// 不论是否 hide in inspector 都要添加到 props,否则 asset watcher 不能正常工作
_appendProp(this, name/*, true*/);
appendProp(cls, propName/*, true*/);
}
if (Object.getOwnPropertyDescriptor(this.prototype, name)) {
Object.defineProperty(this.prototype, name, {
if (d) {
Object.defineProperty(proto, propName, {
get: getter
});
}
else {
Object.defineProperty(this.prototype, name, {
Object.defineProperty(proto, propName, {
get: getter,
configurable: true,
enumerable: true
@@ -194,57 +229,39 @@ var _metaClass = {
}
if (CC_DEV) {
Attr.attr(this, name, {hasGetter: true}); // 方便 editor 做判断
Attr.attr(cls, propName, {hasGetter: true}); // 方便 editor 做判断
}
return this;
},
}
set: function (name, setter) {
if (setter) {
if (CC_DEV) {
var d = Object.getOwnPropertyDescriptor(this.prototype, name);
if (d && d.set) {
cc.error('%s: the setter of "%s" is already defined!', JS.getClassName(this), name);
return this;
return cc.error('"%s": the setter of "%s" is already defined!', name, propName);
}
}
if (CC_DEV) {
Object.defineProperty(this.prototype, name, {
Object.defineProperty(proto, propName, {
set: setter,
configurable: true,
enumerable: true
});
Attr.attr(this, name, { hasSetter: true }); // 方便 editor 做判断
Attr.attr(cls, propName, {hasSetter: true}); // 方便 editor 做判断
}
else {
if (Object.getOwnPropertyDescriptor(this.prototype, name)) {
Object.defineProperty(this.prototype, name, {
if (d) {
Object.defineProperty(proto, propName, {
set: setter
});
}
else {
Object.defineProperty(this.prototype, name, {
Object.defineProperty(proto, propName, {
set: setter,
configurable: true,
enumerable: true
});
}
}
return this;
},
/**
* Create a new Class that inherits from this Class
* @param {Object} options
* @return {Function}
* @deprecated
*/
extend: function (options) {
options.extends = this;
return CCClass(options);
}
};
}
function getDefault (defaultVal) {
if (typeof defaultVal === 'function') {
@@ -266,6 +283,10 @@ function getDefault (defaultVal) {
function instantiateProps (instance, itsClass) {
var propList = itsClass.__props__;
if (propList === null) {
deferredInitializer.init();
propList = itsClass.__props__;
}
for (var i = 0; i < propList.length; i++) {
var prop = propList[i];
var attrs = Attr.attr(itsClass, prop);
@@ -336,21 +357,19 @@ cc.isChildClassOf = function (subclass, superclass) {
function doDefine (className, baseClass, mixins, constructor, options) {
var fireClass = _createCtor(constructor, baseClass, mixins, className, options);
// occupy some non-inherited static members
for (var staticMember in _metaClass) {
Object.defineProperty(fireClass, staticMember, {
value: _metaClass[staticMember],
writable: true
});
}
// extend - (NON-INHERITED) Create a new Class that inherits from this Class
Object.defineProperty(fireClass, 'extend', {
value: function (options) {
options.extends = this;
return CCClass(options);
},
writable: true,
configurable: true
});
if (baseClass) {
// inherit
JS.extend(fireClass, baseClass); // 这里会把父类的 __props__ 复制给子类
//
fireClass.$super = baseClass;
// inherit __props__
fireClass.__props__ = baseClass.__props__ ? baseClass.__props__.slice() : [];
}
if (mixins) {
@@ -363,20 +382,11 @@ function doDefine (className, baseClass, mixins, constructor, options) {
for (var p in mixin)
if (mixin.hasOwnProperty(p) && INVALID_STATICS.indexOf(p) < 0)
fireClass[p] = mixin[p];
// mixin __props__
fireClass.__props__ = fireClass.__props__ || [];
if (mixin.__props__) {
fireClass.__props__ = fireClass.__props__.concat(mixin.__props__.filter(function (x) {
return fireClass.__props__.indexOf(x) < 0;
}));
}
}
// restore constuctor overridden by mixin
fireClass.prototype.constructor = fireClass;
}
fireClass.__props__ = fireClass.__props__ || [];
JS.setClassName(className, fireClass);
return fireClass;
}
@@ -443,7 +453,7 @@ function normalizeClassName (className) {
var DefaultName = 'CCClass';
if (className) {
className = className.replace(/\./g, '_');
className = className.split('').filter(function (x) { return /^[a-zA-Z0-9_$]/.test(x) }).join('');
className = className.split('').filter(function (x) { return /^[a-zA-Z0-9_$]/.test(x); }).join('');
if (/^[0-9]/.test(className[0])) {
className = '_' + className;
}
@@ -558,8 +568,8 @@ function _createCtor (ctor, baseClass, mixins, className, options) {
Object.defineProperty(fireClass, '__ctors__', {
value: ctors.length > 0 ? ctors : null,
writable: false,
enumerable: false
// writable should be false,
// enumerable should be false
});
if (shouldAddProtoCtor && CC_EDITOR) {
@@ -623,6 +633,41 @@ function boundSuperCalls (baseClass, options) {
return hasSuperCall;
}
function declareProperties (cls, className, properties, baseClass, mixins) {
cls.__props__ = [];
if (baseClass && baseClass.__props__) {
cls.__props__ = baseClass.__props__.slice();
}
if (mixins) {
for (var m = 0; m < mixins.length; ++m) {
var mixin = mixins[m];
if (mixin.__props__) {
cls.__props__ = cls.__props__.concat(mixin.__props__.filter(function (x) {
return cls.__props__.indexOf(x) < 0;
}));
}
}
}
if (properties) {
// 预处理属性
preprocessAttrs(properties, className, cls);
for (var propName in properties) {
var val = properties[propName];
var attrs = parseAttributes(val, className, propName);
if ('default' in val) {
defineProp(cls, className, propName, val.default, attrs);
}
else {
defineGetSet(cls, className, propName, val, attrs);
}
}
}
}
/**
* !#en Defines a CCClass using the given specification, please see [Class](/en/scripting/class/) for details.
* !#zh 定义一个 CCClass,传入参数必须是一个包含类型参数的字面量对象,具体用法请查阅[类型定义](/zh/scripting/class/)。
@@ -687,44 +732,28 @@ function CCClass (options) {
var name = options.name;
var base = options.extends/* || CCObject*/;
var mixins = options.mixins;
// create constructor
var cls;
cls = define(name, base, options.mixins, options.ctor, options);
cls = define(name, base, mixins, options.ctor, options);
if (!name) {
name = cc.js.getClassName(cls);
}
// define properties
// define Properties
var properties = options.properties;
if (properties) {
// 预处理属性
preprocessAttrs(properties, name, cls);
for (var propName in properties) {
var val = properties[propName];
var attrs = parseAttributes(val, name, propName);
if ('default' in val) {
cls.prop.apply(cls, [propName, val.default].concat(attrs));
}
else {
var getter = val.get;
var setter = val.set;
if (CC_DEV) {
if (!getter && !setter) {
cc.error('Property %s.%s must define at least one of "default", "get" or "set".', name,
propName);
}
}
if (getter) {
cls.get.apply(cls, [propName, getter].concat(attrs));
}
if (setter) {
cls.set(propName, setter);
}
}
}
if (typeof properties === 'function' ||
(base && base.__props__ === null) ||
(mixins && mixins.some(function (x) {
return x.__props__ === null;
}))
) {
deferredInitializer.push({cls: cls, props: properties, mixins: mixins});
cls.__props__ = null;
}
else {
declareProperties(cls, name, properties, base, options.mixins);
}
// define statics
@@ -789,31 +818,17 @@ function CCClass (options) {
* @private
*/
CCClass._isCCClass = function (constructor) {
return !!constructor && (constructor.prop === _metaClass.prop);
return !!constructor && typeof constructor.__ctors__ !== 'undefined';
};
//
// @method _convertToFireClass
// @param {Function} constructor
// @private
//
//CCClass._convertToFireClass = function (constructor) {
// constructor.prop = _metaClass.prop;
//};
// Optimized define function only for internal base classes
//
// @param {String} className
// @param {Function} constructor
// @param {string[]} serializableFields
// @private
function fastDefine (className, constructor, serializableFields) {
// Optimized define function only for internal classes
CCClass._fastDefine = function (className, constructor, serializableFields) {
JS.setClassName(className, constructor);
constructor.__props__ = serializableFields;
for (var i = 0; i < serializableFields.length; i++) {
Attr.attr(constructor, serializableFields[i], { visible: false });
}
}
};
CCClass.attr = Attr.attr;
@@ -920,6 +935,11 @@ function parseAttributes (attrs, className, propName) {
if (attrs.serializable === false) {
result.push(Attr.NonSerialized);
}
if (CC_EDITOR) {
if ('animatable' in attrs && !attrs.animatable) {
result.push({ animatable: false });
}
}
if (CC_DEV) {
var visible = attrs.visible;
@@ -955,38 +975,9 @@ function parseAttributes (attrs, className, propName) {
}
}
var nullable = attrs.nullable;
if (nullable) {
if (typeof nullable === 'object') {
var boolPropName = nullable.propName;
if (typeof boolPropName === 'string') {
var def = nullable.default;
if (typeof def === 'boolean') {
result.push(Attr.Nullable(boolPropName, def));
}
else if (CC_DEV) {
cc.error(ERR_Type, '"default"', 'nullable object', 'boolean');
}
}
else if (CC_DEV) {
cc.error(ERR_Type, '"propName"', 'nullable object', 'string');
}
}
else if (CC_DEV) {
cc.error(ERR_Type, '"nullable"', className + '.' + propName, 'object');
}
}
return result;
}
/**
* @param {Object} options
* @return {Function}
* @deprecated
*/
CCClass.extend = CCClass;
cc.Class = CCClass;
module.exports = {
@@ -995,5 +986,5 @@ module.exports = {
defaultVal = getDefault(defaultVal);
return Array.isArray(defaultVal);
},
fastDefine: fastDefine
fastDefine: CCClass._fastDefine
};
+1
View File
@@ -374,6 +374,7 @@ cc.KEY = {
/**
* @property {Number} num4
* @readonly
*/
num4:100,
/**
* @property {Number} num5
+1 -1
View File
@@ -114,7 +114,7 @@ switch(cc.__BrowserGetter.adaptationType){
* the standard way to use it is by calling:<br/>
* - cc.view.methodName(); <br/>
*
* @class EGLView
* @class view
* @extends _Class
*/
cc.EGLView = cc._Class.extend(/** @lends cc.view# */{
+10 -4
View File
@@ -641,11 +641,17 @@ else {
_supportWebGL = true;
}
// Ruled out Android 4- except for QQ Brwoser 6.2+
if (sys.os === sys.OS_ANDROID && sys.osMainVersion < 5) {
// Accept only Android 5+ default browser and QQ Brwoser 6.2+
if (sys.os === sys.OS_ANDROID) {
_supportWebGL = false;
// QQ Brwoser 6.2+
var browserVer = parseFloat(sys.browserVersion);
if (sys.browserType !== sys.BROWSER_TYPE_MOBILE_QQ || browserVer < 6.2) {
_supportWebGL = false;
if (sys.browserType === sys.BROWSER_TYPE_MOBILE_QQ && browserVer >= 6.2) {
_supportWebGL = true;
}
// Android 5+ default browser
else if (sys.osMainVersion && sys.osMainVersion >= 5 && sys.browserType === sys.BROWSER_TYPE_ANDROID) {
_supportWebGL = true;
}
}
}
-20
View File
@@ -287,25 +287,6 @@ function RawType (typename) {
};
}
function Nullable (boolPropName, hasValueByDefault) {
return {
nullable: boolPropName,
_onAfterProp: function (constructor, mainPropName) {
// declare boolean
constructor.prop(boolPropName, hasValueByDefault, { visible: false });
// copy attributes from main property
var mainPropAttr = cc.Class.attr(constructor, mainPropName) || {};
if (mainPropAttr.serializable === false) {
cc.Class.attr(constructor, boolPropName, NonSerialized);
}
else if (mainPropAttr.editorOnly) {
cc.Class.attr(constructor, boolPropName, EditorOnly);
}
}
};
}
function Range (min, max) {
return { min: min, max: max };
}
@@ -318,6 +299,5 @@ module.exports = {
ObjectType: ObjectType,
RawType: RawType,
ScriptUuid: {}, // the value will be represented as a uuid string
Nullable: Nullable,
Range: Range
};
+2 -2
View File
@@ -76,7 +76,7 @@ CallbacksHandler.prototype.has = function (key, callback, target) {
if (callbackTarget === target) {
return true;
}
index = list.indexOf(callback, index + 1);
index = cc.js.array.indexOf.call(list, callback, index + 1);
}
// callback given but not found
return false;
@@ -131,7 +131,7 @@ CallbacksHandler.prototype.remove = function (key, callback, target) {
break;
}
index = list.indexOf(callback, index + 1);
index = cc.js.array.indexOf.call(list, callback, index + 1);
}
return true;
}
+4 -1
View File
@@ -484,6 +484,10 @@ var _Deserializer = (function () {
// FACADE
/**
* @module cc
*/
/**
* !#en Deserialize json to cc.Asset
* !#zh 将 JSON 反序列化为对象实例。
@@ -496,7 +500,6 @@ var _Deserializer = (function () {
* @param {deserialize.Details} [result] - additional loading result
* @param {Object} [options]
* @return {object} the main data(asset)
* @module cc
*/
cc.deserialize = function (data, result, options) {
var classFinder = (options && options.classFinder) || JS._getClassById;
+19 -1
View File
@@ -628,7 +628,25 @@ js.array = {
for (i = 0; i < len; i += 1)
arr_clone[i] = array[i];
return arr_clone;
}
},
/**
* Exact same function as Array.prototype.indexOf.
* HACK: ugliy hack for Baidu mobile browser compatibility,
* stupid Baidu guys modify Array.prototype.indexOf for all pages loaded,
* their version changes strict comparison to non-strict comparison,
* it also ignores the second parameter of the original API,
* and this will cause event handler enter infinite loop.
* Baidu developers, if you ever see this documentation,
* here is the standard: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
* Seriously !
*
* @method indexOf
* @param {any} searchElement Element to locate in the array.
* @param {Number} [fromIndex=0] The index to start the search at
* @return {Number} returns the first index at which a given element can be found in the array, or -1 if it is not present.
*/
indexOf: Array.prototype.indexOf,
};
cc.js = js;
+13 -5
View File
@@ -193,12 +193,20 @@ module.exports = function (properties, className, cls) {
properties[propName] = val;
}
if (val) {
if (CC_EDITOR && 'default' in val) {
if (val.get) {
cc.error('The "default" value of "%s.%s" should not be used with a "get" function.', className, propName);
if (CC_EDITOR) {
if ('default' in val) {
if (val.get) {
cc.error('The "default" value of "%s.%s" should not be used with a "get" function.',
className, propName);
}
else if (val.set) {
cc.error('The "default" value of "%s.%s" should not be used with a "set" function.',
className, propName);
}
}
else if (val.set) {
cc.error('The "default" value of "%s.%s" should not be used with a "set" function.', className, propName);
else if (!val.get && !val.set) {
cc.error('Property "%s.%s" must define at least one of "default", "get" or "set".',
className, propName);
}
}
if (!val.override && cls.__props__.indexOf(propName) !== -1 && CC_DEV) {
+59 -29
View File
@@ -51,10 +51,10 @@ EventTarget = require("../cocos2d/core/event/event-target");
* @property {Number} insetBottom - The bottom inset of the 9-slice sprite
*/
cc.SimpleQuadGenerator = {
_rebuildQuads_base : function (spriteFrame, contentSize, colorOpacity) {
_rebuildQuads_base: function (spriteFrame, contentSize, colorOpacity, isTrimmedContentSize) {
var quads = [];
//build vertices
var vertices = this._calculateVertices(spriteFrame, contentSize);
var vertices = this._calculateVertices(spriteFrame, contentSize, isTrimmedContentSize);
//build uvs
var uvs = this._calculateUVs(spriteFrame);
@@ -88,15 +88,31 @@ cc.SimpleQuadGenerator = {
return quads;
},
_calculateVertices : function (spriteFrame, contentSize) {
_calculateVertices: function (spriteFrame, contentSize, isTrimmedContentSize) {
var x0, x3;
var y0, y3;
if (isTrimmedContentSize) {
x0 = 0;
x3 = contentSize.width;
var x0,x3;
var y0,y3;
x0 = 0;
x3 = contentSize.width;
y0 = 0;
y3 = contentSize.height;
} else {
var originalSize = spriteFrame.getOriginalSize();
var rect = spriteFrame.getRect();
var offset = spriteFrame.getOffset();
var scaleX = contentSize.width / originalSize.width;
var scaleY = contentSize.height / originalSize.height;
var trimmLeft = offset.x + (originalSize.width - rect.width) / 2;
var trimmRight = offset.x - (originalSize.width - rect.width) / 2;
var trimmedBottom = offset.y + (originalSize.height - rect.height) / 2;
var trimmedTop = offset.y - (originalSize.height - rect.height) / 2;
y0 = 0;
y3 = contentSize.height;
x0 = trimmLeft * scaleX;
x3 = contentSize.width + trimmRight * scaleX;
y0 = trimmedBottom * scaleY;
y3 = contentSize.height + trimmedTop * scaleY;
}
//apply contentscale factor
x0 = x0 / cc.contentScaleFactor();
@@ -111,7 +127,7 @@ cc.SimpleQuadGenerator = {
return vertices;
},
_calculateUVs : function (spriteFrame) {
_calculateUVs: function (spriteFrame) {
var atlasWidth = spriteFrame._texture.getPixelWidth();
var atlasHeight = spriteFrame._texture.getPixelHeight();
@@ -145,7 +161,7 @@ cc.SimpleQuadGenerator = {
};
cc.Scale9QuadGenerator = {
_rebuildQuads_base : function (spriteFrame, contentSize, colorOpacity,insetLeft, insetRight, insetTop, insetBottom) {
_rebuildQuads_base: function (spriteFrame, contentSize, colorOpacity, insetLeft, insetRight, insetTop, insetBottom) {
var quads = [];
//build vertices
var vertices = this._calculateVertices(spriteFrame, contentSize, insetLeft, insetRight, insetTop, insetBottom);
@@ -186,7 +202,7 @@ cc.Scale9QuadGenerator = {
return quads;
},
_calculateVertices : function (spriteFrame, contentSize, insetLeft, insetRight, insetTop, insetBottom) {
_calculateVertices: function (spriteFrame, contentSize, insetLeft, insetRight, insetTop, insetBottom) {
var leftWidth, centerWidth, rightWidth;
var topHeight, centerHeight, bottomHeight;
@@ -239,7 +255,7 @@ cc.Scale9QuadGenerator = {
return vertices;
},
_calculateUVs : function (spriteFrame, insetLeft, insetRight, insetTop, insetBottom) {
_calculateUVs: function (spriteFrame, insetLeft, insetRight, insetTop, insetBottom) {
var rect = spriteFrame._rect;
var atlasWidth = spriteFrame._texture.getPixelWidth();
var atlasHeight = spriteFrame._texture.getPixelHeight();
@@ -295,7 +311,7 @@ cc.Scale9QuadGenerator = {
};
cc.TiledQuadGenerator = {
_rebuildQuads_base : function (spriteFrame, contentSize, colorOpacity) {
_rebuildQuads_base: function (spriteFrame, contentSize, colorOpacity) {
var quads = [];
//build uvs
@@ -309,8 +325,8 @@ cc.TiledQuadGenerator = {
//build quads
var hRepeat = contentSize.width / rectWidth;
var vRepeat = contentSize.height / rectHeight;
for(var hindex = 0; hindex < Math.ceil(hRepeat); ++hindex) {
for(var vindex = 0; vindex < Math.ceil(vRepeat); ++vindex) {
for (var hindex = 0; hindex < Math.ceil(hRepeat); ++hindex) {
for (var vindex = 0; vindex < Math.ceil(vRepeat); ++vindex) {
var quad;
quad = new cc.V3F_C4B_T2F_Quad();
@@ -320,20 +336,20 @@ cc.TiledQuadGenerator = {
quad._tr.colors = colorOpacity;
quad._bl.vertices = new cc.Vertex3F(rectWidth * hindex, rectHeight * vindex, 0);
quad._br.vertices = new cc.Vertex3F(rectWidth * Math.min(hindex+1, hRepeat), rectHeight * vindex, 0);
quad._tl.vertices = new cc.Vertex3F(rectWidth * hindex, rectHeight * Math.min(vindex+1, vRepeat), 0);
quad._tr.vertices = new cc.Vertex3F(rectWidth * Math.min(hindex+1, hRepeat), rectHeight * Math.min(vindex+1, vRepeat), 0);
quad._br.vertices = new cc.Vertex3F(rectWidth * Math.min(hindex + 1, hRepeat), rectHeight * vindex, 0);
quad._tl.vertices = new cc.Vertex3F(rectWidth * hindex, rectHeight * Math.min(vindex + 1, vRepeat), 0);
quad._tr.vertices = new cc.Vertex3F(rectWidth * Math.min(hindex + 1, hRepeat), rectHeight * Math.min(vindex + 1, vRepeat), 0);
if (!spriteFrame._rotated) {
quad._bl.texCoords = new cc.Tex2F(u0, v0);
quad._br.texCoords = new cc.Tex2F(u0 + (u1 - u0) * Math.min(1,hRepeat - hindex), v0);
quad._tl.texCoords = new cc.Tex2F(u0, v0 + (v1 - v0) * Math.min(1,vRepeat - vindex));
quad._tr.texCoords = new cc.Tex2F(u0 + (u1 - u0) * Math.min(1,hRepeat - hindex), v0 + (v1 - v0) * Math.min(1,vRepeat - vindex));
quad._br.texCoords = new cc.Tex2F(u0 + (u1 - u0) * Math.min(1, hRepeat - hindex), v0);
quad._tl.texCoords = new cc.Tex2F(u0, v0 + (v1 - v0) * Math.min(1, vRepeat - vindex));
quad._tr.texCoords = new cc.Tex2F(u0 + (u1 - u0) * Math.min(1, hRepeat - hindex), v0 + (v1 - v0) * Math.min(1, vRepeat - vindex));
} else {
quad._bl.texCoords = new cc.Tex2F(u0, v1);
quad._br.texCoords = new cc.Tex2F(u0, v1 + (v0-v1) * Math.min(1,hRepeat - hindex));
quad._tl.texCoords = new cc.Tex2F(u0 + (u1-u0) * Math.min(1,vRepeat - vindex), v1);
quad._tr.texCoords = new cc.Tex2F(u0 + (u1-u0) * Math.min(1,vRepeat - vindex), v1 + (v0-v1) * Math.min(1,hRepeat - hindex));
quad._br.texCoords = new cc.Tex2F(u0, v1 + (v0 - v1) * Math.min(1, hRepeat - hindex));
quad._tl.texCoords = new cc.Tex2F(u0 + (u1 - u0) * Math.min(1, vRepeat - vindex), v1);
quad._tr.texCoords = new cc.Tex2F(u0 + (u1 - u0) * Math.min(1, vRepeat - vindex), v1 + (v0 - v1) * Math.min(1, hRepeat - hindex));
}
quads.push(quad);
@@ -342,7 +358,7 @@ cc.TiledQuadGenerator = {
return quads;
},
_calculateUVs : function (spriteFrame) {
_calculateUVs: function (spriteFrame) {
var atlasWidth = spriteFrame._texture.getPixelWidth();
var atlasHeight = spriteFrame._texture.getPixelHeight();
@@ -716,6 +732,8 @@ cc.Scale9Sprite = _ccsg.Node.extend({
_quads: [],
_quadsDirty: true,
_isTrimmedContentSize: true,
ctor: function (textureOrSpriteFrame) {
_ccsg.Node.prototype.ctor.call(this);
this._renderCmd.setState(this._brightState);
@@ -842,6 +860,17 @@ cc.Scale9Sprite = _ccsg.Node.extend({
this._quadsDirty = true;
},
//
enableTrimmedContentSize: function (isTrimmed) {
if (this._isTrimmedContentSize !== isTrimmed) {
this._isTrimmedContentSize = isTrimmed;
this._quadsDirty = true;
}
},
isTrimmedContentSizeEnabled: function () {
return this._isTrimmedContentSize;
},
/**
* Change the state of 9-slice sprite.
* @see `State`
@@ -954,12 +983,13 @@ cc.Scale9Sprite = _ccsg.Node.extend({
this._quads[index]._tr.colors = color;
}
},
_rebuildQuads : function () {
_rebuildQuads: function () {
if (!this.loaded() || this._quadsDirty === false) return;
var color = this.getDisplayedColor();
color.a = this.getDisplayedOpacity();
if (this._renderingType === cc.Scale9Sprite.RenderingType.SIMPLE) {
this._quads = cc.SimpleQuadGenerator._rebuildQuads_base(this._spriteFrame, this.getContentSize(), color);
this._quads = cc.SimpleQuadGenerator._rebuildQuads_base(this._spriteFrame, this.getContentSize(), color, this._isTrimmedContentSize);
} else if (this._renderingType === cc.Scale9Sprite.RenderingType.SLICED) {
this._quads = cc.Scale9QuadGenerator._rebuildQuads_base(this._spriteFrame, this.getContentSize(), color, this._insetLeft, this._insetRight, this._insetTop, this._insetBottom);
} else if (this._renderingType === cc.Scale9Sprite.RenderingType.TILED) {
@@ -1045,7 +1075,7 @@ cc.SpriteType = cc.Enum({
/*
* @property {Number} TILED
*/
TILED : 2,
TILED: 2,
/*
* @property {Number} FILLED
*/
@@ -71,7 +71,7 @@
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
wrapper.setCompositeOperation(node._blendFunc);
wrapper.setCompositeOperation(_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(node._blendFunc));
wrapper.setGlobalAlpha(alpha);
if(this._textureToRender) {
@@ -94,10 +94,10 @@
var textureWidth = this._textureToRender.getPixelWidth();
var textureHeight = this._textureToRender.getPixelHeight();
sx = quads[i]._bl.texCoords.u * textureWidth;
sy = quads[i]._bl.texCoords.v * textureHeight;
sx = quads[i]._tl.texCoords.u * textureWidth;
sy = quads[i]._tl.texCoords.v * textureHeight;
sw = (quads[i]._tr.texCoords.u - quads[i]._bl.texCoords.u) * textureWidth;
sh = (quads[i]._tr.texCoords.v - quads[i]._bl.texCoords.v) * textureHeight;
sh = (quads[i]._bl.texCoords.v - quads[i]._tr.texCoords.v) * textureHeight;
x = x * scaleX;
y = y * scaleY;
@@ -109,9 +109,11 @@
wrapper.setFillStyle(context.createPattern(image, this._textureToRender._pattern));
context.fillRect(x, y, w, h);
} else {
context.drawImage(image,
sx, sy, sw, sh,
x, y, w, h);
if(sw !== 0 && sh !== 0 && w !== 0 && h !== 0) {
context.drawImage(image,
sx, sy, sw, sh,
x, y, w, h);
}
}
}
+2 -1
View File
@@ -281,12 +281,13 @@ var Texture2D = cc.Class(/** @lends cc.Texture2D# */{
*/
handleLoadedTexture: function () {
var self = this;
if (self._textureLoaded) return;
if (!self._htmlElementObj) {
var img = cc.loader.getRes(self.url);
if (!img) return;
self.initWithElement(img);
}
if (!self._htmlElementObj.width || !self._htmlElementObj.height)
return;
var locElement = self._htmlElementObj;
self._contentSize.width = locElement.width;
+4
View File
@@ -144,6 +144,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
oldParent._children.splice(removeAt, 1);
oldParent.emit(CHILD_REMOVED, removeAt);
this._onHierarchyChanged(oldParent);
if (CC_EDITOR) {
_Scene.DetectConflict.afterAddChild(this);
}
}
}
else if (value) {
+5 -2
View File
@@ -646,7 +646,11 @@ var ParticleSystem = cc.Class({
// OVERRIDE METHODS
_createSgNode: function () {
var sgNode = this._sgNode = new _ccsg.ParticleSystem();
return new _ccsg.ParticleSystem();
},
_initSgNode: function () {
var sgNode = this._sgNode;
var loadCustomAfterFile = false;
if (this._file) {
@@ -660,7 +664,6 @@ var ParticleSystem = cc.Class({
// stop by default
sgNode.stopSystem();
return sgNode;
},
// APIS
+21 -25
View File
@@ -17,18 +17,18 @@ var handleErrors = require('../util/handleErrors');
require('./build-cocos2d');
function getUglifyOptions (minify, global_defs, preserveComments) {
preserveComments = preserveComments || false;
function getUglifyOptions (minify, global_defs) {
if (minify) {
return {
compress: {
global_defs: global_defs
global_defs: global_defs,
conditionals: false, // 如果为 true, 会把 if 压缩成 bool 表达式, 但 sourcemap 的行号就会乱掉
}
};
}
else {
// http://lisperator.net/uglifyjs/compress
var compress = {
// http://lisperator.net/uglifyjs/compress
global_defs: global_defs,
sequences: false, // join consecutive statements with the “comma operator”
properties: false, // optimize property access: a["foo"] → a.foo
@@ -49,11 +49,11 @@ function getUglifyOptions (minify, global_defs, preserveComments) {
side_effects: false // drop side-effect-free statements
//warnings: true // warn about potentially dangerous optimizations/code
};
// http://lisperator.net/uglifyjs/codegen
return {
mangle: false,
preserveComments: preserveComments,
//preserveComments: 'all',
output: {
// http://lisperator.net/uglifyjs/codegen
beautify: true,
bracketize: true
},
@@ -63,32 +63,28 @@ function getUglifyOptions (minify, global_defs, preserveComments) {
}
function rebundle(bundler) {
var bundle = bundler.bundle()
.on('error', handleErrors.handler)
.pipe(handleErrors())
.pipe(source(paths.outFile))
.pipe(buffer());
var dev = sourcemaps.init({loadMaps: true})
.pipe(uglify(getUglifyOptions(false, {
CC_EDITOR: false,
CC_DEV: true,
CC_TEST: false
})))
.pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true}))
.pipe(gulp.dest(paths.outDir));
var dev = uglify(getUglifyOptions(false, {
CC_EDITOR: false,
CC_DEV: false,
CC_TEST: false
}));
var min = rename({ suffix: '-min' });
min.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify(getUglifyOptions(true, {
min.pipe(uglify(getUglifyOptions(true, {
CC_EDITOR: false,
CC_DEV: false,
CC_TEST: false
})))
})));
return bundler.bundle()
.on('error', handleErrors.handler)
.pipe(handleErrors())
.pipe(source(paths.outFile))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(mirror(dev, min))
.pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true}))
.pipe(gulp.dest(paths.outDir));
return bundle.pipe(mirror(dev, min));
}
function rebundle_test(bundler, suffix) {
+60
View File
@@ -411,6 +411,18 @@ test('statics', function () {
cc.js.unregisterClass(Animal, Dog, Labrador);
});
test('_isCCClass', function () {
strictEqual(cc.Class._isCCClass(cc.Class({})), true, 'should be CCClass');
function ctor () {
this.foo = 0;
}
cc.Class._fastDefine('T', ctor, ['foo']);
strictEqual(cc.Class._isCCClass(ctor), false, 'fastDefined ctor should not recognized as CCClass');
cc.js.unregisterClass(ctor);
});
test('try catch', function () {
var originThrow = cc._throw;
@@ -567,3 +579,51 @@ test('mixins', function () {
strictEqual(cc.Class.attr(BigDog, 'p2').default, 'Defined by Mixin2', 'last mixin property should override previous');
strictEqual(cc.Class.attr(BigDog, 'p1').default, 'Defined by BigDog', "should override base property");
});
asyncTest('instantiate properties in the next frame', function () {
var Dog = cc.Class({
properties: function () {
return {
like: 'shit'
};
}
});
var Husky = cc.Class({
extends: Dog,
properties: {
weight: 100
}
});
throws(
function () {
Husky.__props__.length;
},
'should raised error if accessing to props via Class'
);
setTimeout(function () {
deepEqual(Husky.__props__, ['like', 'weight'], 'should get properties in the correct order');
start();
}, 0);
});
test('lazy instantiate properties', function () {
var Dog = cc.Class({
properties: function () {
return {
like: 'shit'
};
}
});
var Husky = cc.Class({
extends: Dog,
properties: {
weight: 100
}
});
var dog = new Husky();
deepEqual(Husky.__props__, ['like', 'weight'], 'could get properties in the correct order after instantiating');
});
@@ -40,7 +40,6 @@ var createEntity = function (file, x, y) {
var spriteFrame = new cc.SpriteFrame(tex, cc.rect(0, 0, tex.getPixelWidth(), tex.getPixelHeight()));
var spriteRenderer = node.addComponent(cc.Sprite);
spriteRenderer.spriteFrame = spriteFrame;
spriteRenderer._createSgNode();
}
node.x = x;
node.y = y;