diff --git a/cocos2d/core/platform/instantiate.js b/cocos2d/core/platform/instantiate.js
index 8596bd299b..95a6341bf6 100644
--- a/cocos2d/core/platform/instantiate.js
+++ b/cocos2d/core/platform/instantiate.js
@@ -30,16 +30,10 @@ var Attr = require('./attribute');
var _isDomNode = require('./utils').isDomNode;
/**
- * !#en Clones the object original and returns the clone.
+ * !#en Clones the object `original` and returns the clone, or instantiate a node from the Prefab.
+ * !#zh 克隆指定的任意类型的对象,或者从 Prefab 实例化出新节点。
*
- * See [Clone exists Entity](/en/scripting/create-destroy-entities/#instantiate)
- *
- * !#zh 复制给定的对象
- *
- * 详细用法可参考[复制已有Entity](/zh/scripting/create-destroy-entities/#instantiate)
- *
- * Instantiate 时,function 和 dom 等非可序列化对象会直接保留原有引用,Asset 会直接进行浅拷贝,可序列化类型会进行深拷贝。
- * 对于 Entity / Component 等 Scene Object,如果对方也会被一起 Instantiate,则重定向到新的引用,否则保留为原来的引用。
+ * (Instantiate 时,function 和 dom 等非可序列化对象会直接保留原有引用,Asset 会直接进行浅拷贝,可序列化类型会进行深拷贝。)
*
* @method instantiate
* @param {Prefab|Node|Object} original - An existing object that you want to make a copy of.
@@ -47,25 +41,39 @@ var _isDomNode = require('./utils').isDomNode;
* @typescript
* instantiate(original: Prefab): Node
* instantiate(original: T): T
+ * @example
+ * // instantiate node from prefab
+ * var scene = cc.director.getScene();
+ * var node = cc.instantiate(prefabAsset);
+ * node.parent = scene;
+ * // clone node
+ * var scene = cc.director.getScene();
+ * var node = cc.instantiate(targetNode);
+ * node.parent = scene;
*/
-function instantiate (original) {
- if (typeof original !== 'object' || Array.isArray(original)) {
- if (CC_DEV) {
- cc.errorID(6900);
+function instantiate (original, internal_force) {
+ if (!internal_force) {
+ if (typeof original !== 'object' || Array.isArray(original)) {
+ if (CC_DEV) {
+ cc.errorID(6900);
+ }
+ return null;
}
- return null;
- }
- if (!original) {
- if (CC_DEV) {
- cc.errorID(6901);
+ if (!original) {
+ if (CC_DEV) {
+ cc.errorID(6901);
+ }
+ return null;
}
- return null;
- }
- if (!cc.isValid(original)) {
- if (CC_DEV) {
- cc.errorID(6902);
+ if (!cc.isValid(original)) {
+ if (CC_DEV) {
+ cc.errorID(6902);
+ }
+ return null;
+ }
+ if (CC_DEV && original instanceof cc.Component) {
+ cc.warn('Should not instantiate a single cc.Component directly, you must instantiate the entire node.');
}
- return null;
}
var clone;
diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js
index 3b59b3017c..7a61dbdac2 100644
--- a/cocos2d/core/sprites/CCSpriteFrame.js
+++ b/cocos2d/core/sprites/CCSpriteFrame.js
@@ -451,6 +451,10 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
}
},
+ // _instantiate () {
+ // var clone = new cc.SpriteFrame();
+ // },
+
// SERIALIZATION
_serialize: CC_EDITOR && function (exporting) {