diff --git a/cocos2d/animation/animation-manager.js b/cocos2d/animation/animation-manager.js
index d798be9a77..0afe8c6910 100644
--- a/cocos2d/animation/animation-manager.js
+++ b/cocos2d/animation/animation-manager.js
@@ -3,6 +3,7 @@ var JS = cc.js;
var AnimationManager = cc.Class({
ctor: function () {
this.animators = [];
+ this.__instanceId = cc.ClassManager.getNewInstanceId();
},
// for manager
diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js
index 5271aa0b31..34137f8875 100644
--- a/cocos2d/core/CCGame.js
+++ b/cocos2d/core/CCGame.js
@@ -224,7 +224,9 @@ var game = /** @lends cc.game# */{
*/
cc.winSize = cc.director.getWinSize();
- this._initEvents();
+ if (!CC_EDITOR) {
+ this._initEvents();
+ }
this._setAnimFrame();
this._runMainLoop();
diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js
index 28a4020b7e..682d6a8f18 100644
--- a/cocos2d/core/CCNode.js
+++ b/cocos2d/core/CCNode.js
@@ -376,6 +376,10 @@ var Node = cc.Class({
this._parent = null;
}
}
+ else {
+ this._sgNode.release();
+ this._sgNode = null;
+ }
},
// COMPONENT
diff --git a/cocos2d/core/assets/CCRawAsset.js b/cocos2d/core/assets/CCRawAsset.js
index c1c4288e82..755452941b 100644
--- a/cocos2d/core/assets/CCRawAsset.js
+++ b/cocos2d/core/assets/CCRawAsset.js
@@ -24,6 +24,16 @@ cc.RawAsset = cc.Class({
* @param {Object} callback.node - the created node or null
*/
createNodeByInfo: null,
+
+ /**
+ * @method isRawAssetType
+ * @param {Function} ctor
+ * @returns {Boolean}
+ * @private
+ */
+ isRawAssetType: function (ctor) {
+ return cc.isChildClassOf(ctor, cc.RawAsset) && !cc.isChildClassOf(ctor, cc.Asset);
+ }
}
});
diff --git a/cocos2d/core/components/CCCanvas.js b/cocos2d/core/components/CCCanvas.js
index 3973ca7f22..879c5ed35d 100644
--- a/cocos2d/core/components/CCCanvas.js
+++ b/cocos2d/core/components/CCCanvas.js
@@ -132,6 +132,9 @@ var Canvas = cc.Class({
},
onLoad: function () {
+ var Flags = cc.Object.Flags;
+ this._objFlags |= (Flags.IsPositionLocked | Flags.IsAnchorLocked | Flags.IsSizeLocked);
+
if (Canvas.instance) {
return cc.error("Can't init canvas '%s' because it conflicts with the existing '%s', the scene should only have one active canvas at the same time",
this.node.name, Canvas.instance.node.name);
diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js
index f47605f250..d9b69e0f48 100644
--- a/cocos2d/core/components/CCComponent.js
+++ b/cocos2d/core/components/CCComponent.js
@@ -47,8 +47,8 @@ function callOnEnable (self, enable) {
self.onEnable();
}
}
-
- cc.director.getScheduler().resumeTarget(this);
+
+ cc.director.getScheduler().resumeTarget(self);
_registerEvent(self, true);
@@ -66,7 +66,7 @@ function callOnEnable (self, enable) {
}
}
- cc.director.getScheduler().pauseTarget(this);
+ cc.director.getScheduler().pauseTarget(self);
_registerEvent(self, false);
@@ -577,7 +577,7 @@ var Component = cc.Class({
isRunning: function () {
return this.enabledInHierarchy;
},
-
+
/**
*
Schedules a custom selector.
* If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.
diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js
index 7f037bfaa0..903b923bf3 100644
--- a/cocos2d/core/platform/CCClass.js
+++ b/cocos2d/core/platform/CCClass.js
@@ -775,10 +775,10 @@ function FireClass (options) {
else if (CC_DEV) {
var correct = TYPO_TO_CORRECT[funcName];
if (correct) {
- cc.warn('Unknown parameter of %s.%s, maybe you want is "%s".', name, funcName, correct);
+ cc.warn('Unknown type of %s.%s, maybe you want is "%s".', name, funcName, correct);
}
else if (func) {
- cc.error('Unknown parameter of %s.%s, property should be defined in "properties" or "ctor"', name, funcName);
+ cc.error('Unknown type of %s.%s, property should be defined in "properties" or "ctor"', name, funcName);
}
}
}
@@ -819,15 +819,12 @@ FireClass._isCCClass = function (constructor) {
// constructor.prop = _metaClass.prop;
//};
+// Optimized define function only for internal base classes
//
-// Specially optimized define function only for internal base classes
-//
-// @method _fastDefine
// @param {String} className
// @param {Function} constructor
// @param {string[]} serializableFields
// @private
-//
function fastDefine (className, constructor, serializableFields) {
JS.setClassName(className, constructor);
constructor.__props__ = serializableFields;
diff --git a/cocos2d/core/platform/CCObject.js b/cocos2d/core/platform/CCObject.js
index 922136c59b..34e7ab3405 100644
--- a/cocos2d/core/platform/CCObject.js
+++ b/cocos2d/core/platform/CCObject.js
@@ -17,6 +17,12 @@ var IsOnEnableCalled = 1 << 12;
var IsOnLoadCalled = 1 << 13;
var IsOnStartCalled = 1 << 14;
+var IsPositionLocked = 1 << 15;
+var IsRotationLocked = 1 << 16;
+var IsScaleLocked = 1 << 17;
+var IsAnchorLocked = 1 << 18;
+var IsSizeLocked = 1 << 19;
+
var Hide = HideInGame | HideInEditor;
// should not clone or serialize these flags
var PersistentMask = ~(ToDestroy | Dirty | Destroying | DontDestroy |
@@ -120,7 +126,13 @@ CCObject.Flags = {
IsOnLoadCalled: IsOnLoadCalled,
IsOnEnableCalled: IsOnEnableCalled,
- IsOnStartCalled: IsOnStartCalled
+ IsOnStartCalled: IsOnStartCalled,
+
+ IsPositionLocked: IsPositionLocked,
+ IsRotationLocked: IsRotationLocked,
+ IsScaleLocked: IsScaleLocked,
+ IsAnchorLocked: IsAnchorLocked,
+ IsSizeLocked: IsSizeLocked,
};
require('./CCClass').fastDefine('cc.Object', CCObject, ['_name', '_objFlags']);
diff --git a/cocos2d/core/platform/preprocess-attrs.js b/cocos2d/core/platform/preprocess-attrs.js
index c44bf155f2..3d8a0224d5 100644
--- a/cocos2d/core/platform/preprocess-attrs.js
+++ b/cocos2d/core/platform/preprocess-attrs.js
@@ -122,8 +122,7 @@ function parseType (val, type, className, propName) {
}
if (CC_EDITOR) {
if (typeof type === 'function') {
- var isRaw = cc.isChildClassOf(type, cc.RawAsset) && !cc.isChildClassOf(type, cc.Asset);
- if (isRaw) {
+ if (cc.RawAsset.isRawAssetType(type)) {
cc.warn('The "type" attribute of "%s.%s" must be child class of cc.Asset, ' +
'otherwise you should use "url: %s" instead', className, propName,
cc.js.getClassName(type));
@@ -149,13 +148,35 @@ function postCheckType (val, type, className, propName) {
module.exports = function (properties, className) {
for (var propName in properties) {
var val = properties[propName];
-
- var isObj = val && typeof val === 'object' && !Array.isArray(val);
- var isLiteral = isObj && val.constructor === Object;
+ var isLiteral = val && val.constructor === Object;
if ( !isLiteral ) {
- properties[propName] = val = {
- default: val
- };
+ if (Array.isArray(val) && val.length > 0) {
+ val = {
+ default: [],
+ type: val
+ };
+ }
+ else if (typeof val === 'function') {
+ if (cc.isChildClassOf(val, cc.ValueType)) {
+ //noinspection JSUnresolvedFunction
+ val = {
+ default: new val(),
+ type: val
+ };
+ }
+ else {
+ val = {
+ default: cc.RawAsset.isRawAssetType(val) ? '' : null,
+ type: val
+ };
+ }
+ }
+ else {
+ val = {
+ default: val
+ };
+ }
+ properties[propName] = val;
}
if (val) {
var notify = val.notify;
diff --git a/test/qunit/unit/test-animation.js b/test/qunit/unit/test-animation.js
index 948f85b9a5..aedd9ce7b7 100644
--- a/test/qunit/unit/test-animation.js
+++ b/test/qunit/unit/test-animation.js
@@ -541,6 +541,7 @@ test('CCAnimation._updateClip', function () {
};
animation._updateClip(newClip);
+ animation.sample();
var clips = animation.getClips();
diff --git a/test/qunit/unit/test-class.js b/test/qunit/unit/test-class.js
index 76b4e48e0a..0c84d064a3 100644
--- a/test/qunit/unit/test-class.js
+++ b/test/qunit/unit/test-class.js
@@ -12,9 +12,11 @@ test('test', function () {
tooltip: 'Float',
displayName: 'displayName'
},
- eat: function () {
- return function () {
- return 'eating';
+ eat: {
+ default: function () {
+ return function () {
+ return 'eating';
+ }
}
},
weight: {
@@ -110,6 +112,33 @@ test('test', function () {
cc.js.unregisterClass(Animal, Labrador);
});
+test('define property in quick way', function () {
+ var Class = cc.Class({
+ properties: {
+ undefinedVal: undefined,
+ nullVal: null,
+ string: '...',
+ array: [],
+ node: cc.Node,
+ rawAsset: cc.Texture2D,
+ asset: cc.SpriteFrame,
+ vec2: cc.Vec2,
+ vec2_one: cc.Vec2.ONE,
+ }
+ });
+ var obj = new Class();
+
+ strictEqual(obj.undefinedVal, undefined, 'could define default value of undefined');
+ strictEqual(obj.nullVal, null, 'could define default value of null');
+ strictEqual(obj.string, '...', 'could define default value of string');
+ deepEqual(obj.array, [], 'could define default value of array');
+ strictEqual(obj.node, null, 'could define default value of cc.Node');
+ strictEqual(obj.rawAsset, '', 'could define default value of raw asset');
+ strictEqual(obj.asset, null, 'could define default value of asset');
+ ok(obj.vec2.equals(cc.Vec2.ZERO), 'could define default value by using cc.Vec2');
+ ok(obj.vec2_one.equals(cc.Vec2.ONE), 'could define default value by using cc.Vec2.ONE');
+});
+
test('Inherit', function () {
var Animal = cc.Class({
name: 'cc.Animal',
diff --git a/test/qunit/unit/test-node.js b/test/qunit/unit/test-node.js
index ee6fc71bb7..2a6068aa82 100644
--- a/test/qunit/unit/test-node.js
+++ b/test/qunit/unit/test-node.js
@@ -392,3 +392,25 @@ test('attach events', function () {
cc.engine.off('node-attach-to-scene', onAttach);
cc.engine.off('node-detach-from-scene', onDetach);
});
+
+test('release sg node', function () {
+ var parent = new cc.Node();
+ var child = new cc.Node();
+ child.parent = parent;
+
+ var childReleased = false;
+ var parentReleased = false;
+
+ child._sgNode.release = function () {
+ childReleased = true;
+ };
+ parent._sgNode.release = function () {
+ parentReleased = true;
+ };
+
+ parent.destroy();
+ cc.Object._deferredDestroy();
+
+ strictEqual(parentReleased, true, 'should release parent sg node');
+ strictEqual(childReleased, true, 'should release child sg node');
+});