remove unused texture (path) support for constructor of sgNodes

This commit is contained in:
Jare Guo
2017-09-06 16:37:48 +08:00
parent d988405377
commit ebd794bd6d
3 changed files with 19 additions and 50 deletions
+13 -32
View File
@@ -52,19 +52,15 @@ var Misc = require('../utils/misc');
* @class
* @extends _ccsg.Node
*
* @param {String|cc.SpriteFrame|HTMLImageElement|cc.Texture2D} fileName The string which indicates a path to image file, e.g., "scene1/monster.png".
* @param {cc.SpriteFrame|cc.Texture2D} textureOrSpriteFrame
* @param {Rect} rect Only the contents inside rect of pszFileName's texture will be applied for this sprite.
* @param {Boolean} [rotated] Whether or not the texture rectangle is rotated.
* @example
*
* 1.Create a sprite with image path and rect
* var sprite1 = new _ccsg.Sprite("res/HelloHTML5World.png");
* var sprite2 = new _ccsg.Sprite("res/HelloHTML5World.png",cc.rect(0,0,480,320));
*
* 2.Create a sprite with a sprite frame
* 1.Create a sprite with a sprite frame
* var sprite = new _ccsg.Sprite(spriteFrame);
*
* 3.Create a sprite with an existing texture contained in a CCTexture2D object
* 2.Create a sprite with an existing texture contained in a CCTexture2D object
* After creation, the rect will be the size of the texture, and the offset will be (0,0).
* var texture = cc.textureCache.addImage("HelloHTML5World.png");
* var sprite1 = new _ccsg.Sprite(texture);
@@ -113,7 +109,7 @@ _ccsg.Sprite = _ccsg.Node.extend({
_textureLoaded:false,
_className:"Sprite",
ctor: function (fileName, rect, rotated) {
ctor: function (textureOrSpriteFrame, rect, rotated) {
var self = this;
_ccsg.Node.prototype.ctor.call(self);
EventTarget.call(self);
@@ -124,7 +120,7 @@ _ccsg.Sprite = _ccsg.Node.extend({
self._blendFunc = {src: cc.macro.BLEND_SRC, dst: cc.macro.BLEND_DST};
self._rect = cc.rect(0, 0, 0, 0);
self._softInit(fileName, rect, rotated);
self._softInit(textureOrSpriteFrame, rect, rotated);
},
/**
@@ -367,30 +363,15 @@ _ccsg.Sprite = _ccsg.Node.extend({
return this._texture;
},
_softInit: function (fileName, rect, rotated) {
if (fileName === undefined)
_softInit: function (textureOrSpriteFrame, rect, rotated) {
if (textureOrSpriteFrame === undefined)
_ccsg.Sprite.prototype.init.call(this);
else if (cc.js.isString(fileName)) {
if (fileName[0] === "#") {
cc.logID(2728, fileName);
} else {
// Init with filename and rect
_ccsg.Sprite.prototype.init.call(this, fileName, rect);
}
} else if (typeof fileName === "object") {
if (fileName instanceof cc.Texture2D) {
// Init with texture and rect
this.initWithTexture(fileName, rect, rotated);
} else if (fileName instanceof cc.SpriteFrame) {
// Init with a sprite frame
this.initWithSpriteFrame(fileName);
} else if ((fileName instanceof HTMLImageElement) || (fileName instanceof HTMLCanvasElement)) {
// Init with a canvas or image element
var texture2d = new cc.Texture2D();
texture2d.initWithElement(fileName);
texture2d.handleLoadedTexture();
this.initWithTexture(texture2d);
}
else if (textureOrSpriteFrame instanceof cc.Texture2D) {
// Init with texture and rect
this.initWithTexture(textureOrSpriteFrame, rect, rotated);
} else if (textureOrSpriteFrame instanceof cc.SpriteFrame) {
// Init with a sprite frame
this.initWithSpriteFrame(textureOrSpriteFrame);
}
},
+3 -6
View File
@@ -1101,7 +1101,7 @@ cc.Scale9Sprite = _ccsg.Node.extend({
_distortionTiling: null,
_meshPolygonInfo: null,
ctor: function (textureOrSpriteFrame) {
ctor: function (spiteFrame) {
_ccsg.Node.prototype.ctor.call(this);
this._renderCmd.setState(this._brightState);
this._blendFunc = cc.BlendFunc._alphaNonPremultiplied();
@@ -1113,11 +1113,8 @@ cc.Scale9Sprite = _ccsg.Node.extend({
this._vertices = dataPool.get(8) || new Float32Array(8);
this._uvs = dataPool.get(8) || new Float32Array(8);
// Init sprite frame
if (typeof textureOrSpriteFrame === 'string' || textureOrSpriteFrame instanceof cc.Texture2D) {
this.initWithTexture(textureOrSpriteFrame);
}
else if (textureOrSpriteFrame instanceof cc.SpriteFrame) {
this.initWithSpriteFrame(textureOrSpriteFrame);
if (spiteFrame) {
this.initWithSpriteFrame(spiteFrame);
}
if (webgl === undefined) {
+3 -12
View File
@@ -58,19 +58,10 @@ cc.SpriteBatchNode = _ccsg.Node.extend(/** @lends cc.SpriteBatchNode# */{
_texture: null,
_className: "SpriteBatchNode",
ctor: function (fileImage) {
ctor: function (texture) {
_ccsg.Node.prototype.ctor.call(this);
this._blendFunc = new cc.BlendFunc(cc.macro.BLEND_SRC, cc.macro.BLEND_DST);
var texture2D;
if (cc.js.isString(fileImage)) {
texture2D = cc.textureCache.getTextureForKey(fileImage);
if (!texture2D)
texture2D = cc.textureCache.addImage(fileImage);
}else if (fileImage instanceof cc.Texture2D)
texture2D = fileImage;
texture2D && this.initWithTexture(texture2D);
texture && this.initWithTexture(texture);
},
// property
@@ -153,7 +144,7 @@ cc.SpriteBatchNode = _ccsg.Node.extend(/** @lends cc.SpriteBatchNode# */{
appendChild: function (sprite) {
this.sortAllChildren();
var lastLocalZOrder = this._children[this._children.length-1]._localZOrder;
this.addChild(sprite. lastLocalZOrder + 1);
this.addChild(sprite, lastLocalZOrder + 1);
},
/**