mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge branch 'master' of github.com:cocos-creator/engine into refactor_ccNode
This commit is contained in:
@@ -38,20 +38,18 @@ var BitmapFont = cc.Class({
|
||||
extends: cc.Font,
|
||||
|
||||
properties: {
|
||||
texture: {
|
||||
default: '',
|
||||
url: cc.Texture2D
|
||||
fntDataStr: {
|
||||
default: ''
|
||||
},
|
||||
|
||||
spriteFrame: {
|
||||
default: null,
|
||||
type: cc.SpriteFrame
|
||||
},
|
||||
|
||||
fontSize: {
|
||||
default: -1
|
||||
}
|
||||
},
|
||||
|
||||
_preloadRawFiles: function (done) {
|
||||
// preload fnt file. (texture already loaded in properties)
|
||||
var fntUrl = this.rawUrl;
|
||||
cc.loader.load({ url: fntUrl, ignoreMaxConcurrency: true }, done);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ require('./CCAsset');
|
||||
require('./CCFont');
|
||||
require('./CCPrefab');
|
||||
require('./CCAudioClip');
|
||||
require('./CCBitmapFont');
|
||||
require('./CCScripts');
|
||||
require('./CCSceneAsset');
|
||||
require('../sprites/CCSpriteFrame');
|
||||
require('../textures/CCTexture2D');
|
||||
require('./CCTTFFont');
|
||||
require('./CCSpriteAtlas');
|
||||
require('./CCBitmapFont');
|
||||
//require('./CCTextAsset');
|
||||
|
||||
@@ -373,9 +373,13 @@ var Label = cc.Class({
|
||||
}
|
||||
|
||||
var isAsset = value instanceof cc.Font;
|
||||
var fntRawUrl = isAsset ? value.rawUrl : '';
|
||||
var textureUrl = isAsset ? value.texture : '';
|
||||
this._sgNode.setFontFileOrFamily(fntRawUrl, textureUrl);
|
||||
|
||||
if (this.font instanceof cc.BitmapFont) {
|
||||
this._sgNode.setFontFileOrFamily(this.font.fntDataStr, this.font.spriteFrame);
|
||||
} else {
|
||||
var ttfName = isAsset ? value.rawUrl : '';
|
||||
this._sgNode.setFontFileOrFamily(ttfName);
|
||||
}
|
||||
}
|
||||
|
||||
if (value instanceof cc.BitmapFont) {
|
||||
@@ -462,19 +466,21 @@ var Label = cc.Class({
|
||||
}
|
||||
|
||||
var isAsset = this.font instanceof cc.Font;
|
||||
var fntRawUrl = isAsset ? this.font.rawUrl : '';
|
||||
var textureUrl = isAsset ? this.font.texture : '';
|
||||
|
||||
var sgNode;
|
||||
if (this.font instanceof cc.BitmapFont) {
|
||||
this._bmFontOriginalSize = this.font.fontSize;
|
||||
sgNode = this._sgNode = new _ccsg.Label(this.string, this.font.fntDataStr, this.font.spriteFrame);
|
||||
} else {
|
||||
var ttfName = isAsset ? this.font.rawUrl : '';
|
||||
sgNode = this._sgNode = new _ccsg.Label(this.string, ttfName);
|
||||
}
|
||||
|
||||
var sgNode = this._sgNode = new _ccsg.Label(this.string, fntRawUrl, textureUrl);
|
||||
sgNode.setVisible(false);
|
||||
|
||||
if (CC_JSB) {
|
||||
sgNode.retain();
|
||||
}
|
||||
|
||||
sgNode.setVisible(false);
|
||||
sgNode.setHorizontalAlign( this.horizontalAlign );
|
||||
sgNode.setVerticalAlign( this.verticalAlign );
|
||||
sgNode.setFontSize( this._fontSize );
|
||||
|
||||
+137
-35
@@ -25,7 +25,93 @@
|
||||
****************************************************************************/
|
||||
|
||||
var EventTarget = require("../cocos2d/core/event/event-target");
|
||||
cc.fontFamilyCache = {};
|
||||
|
||||
var FntLoader = {
|
||||
INFO_EXP: /info [^\n]*(\n|$)/gi,
|
||||
COMMON_EXP: /common [^\n]*(\n|$)/gi,
|
||||
PAGE_EXP: /page [^\n]*(\n|$)/gi,
|
||||
CHAR_EXP: /char [^\n]*(\n|$)/gi,
|
||||
KERNING_EXP: /kerning [^\n]*(\n|$)/gi,
|
||||
ITEM_EXP: /\w+=[^ \r\n]+/gi,
|
||||
INT_EXP: /^[\-]?\d+$/,
|
||||
|
||||
_parseStrToObj: function (str) {
|
||||
var arr = str.match(this.ITEM_EXP);
|
||||
var obj = {};
|
||||
if (arr) {
|
||||
for (var i = 0, li = arr.length; i < li; i++) {
|
||||
var tempStr = arr[i];
|
||||
var index = tempStr.indexOf("=");
|
||||
var key = tempStr.substring(0, index);
|
||||
var value = tempStr.substring(index + 1);
|
||||
if (value.match(this.INT_EXP)) value = parseInt(value);
|
||||
else if (value[0] === '"') value = value.substring(1, value.length - 1);
|
||||
obj[key] = value;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse Fnt string.
|
||||
* @param fntStr
|
||||
* @returns {{}}
|
||||
*/
|
||||
parseFnt: function (fntStr) {
|
||||
var self = this, fnt = {};
|
||||
//padding
|
||||
var infoObj = self._parseStrToObj(fntStr.match(self.INFO_EXP)[0]);
|
||||
var paddingArr = infoObj["padding"].split(",");
|
||||
var padding = {
|
||||
left: parseInt(paddingArr[0]),
|
||||
top: parseInt(paddingArr[1]),
|
||||
right: parseInt(paddingArr[2]),
|
||||
bottom: parseInt(paddingArr[3])
|
||||
};
|
||||
|
||||
//common
|
||||
var commonObj = self._parseStrToObj(fntStr.match(self.COMMON_EXP)[0]);
|
||||
fnt.commonHeight = commonObj["lineHeight"];
|
||||
fnt.fontSize = infoObj["size"];
|
||||
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
|
||||
var texSize = cc.configuration.getMaxTextureSize();
|
||||
if (commonObj["scaleW"] > texSize.width || commonObj["scaleH"] > texSize.height)
|
||||
cc.log("cc.LabelBMFont._parseCommonArguments(): page can't be larger than supported");
|
||||
}
|
||||
if (commonObj["pages"] !== 1) cc.log("cc.LabelBMFont._parseCommonArguments(): only supports 1 page");
|
||||
|
||||
//page
|
||||
var pageObj = self._parseStrToObj(fntStr.match(self.PAGE_EXP)[0]);
|
||||
if (pageObj["id"] !== 0) cc.log("cc.LabelBMFont._parseImageFileName() : file could not be found");
|
||||
fnt.atlasName = pageObj["file"];
|
||||
|
||||
//char
|
||||
var charLines = fntStr.match(self.CHAR_EXP);
|
||||
var fontDefDictionary = fnt.fontDefDictionary = {};
|
||||
for (var i = 0, li = charLines.length; i < li; i++) {
|
||||
var charObj = self._parseStrToObj(charLines[i]);
|
||||
var charId = charObj["id"];
|
||||
fontDefDictionary[charId] = {
|
||||
rect: {x: charObj["x"], y: charObj["y"], width: charObj["width"], height: charObj["height"]},
|
||||
xOffset: charObj["xoffset"],
|
||||
yOffset: charObj["yoffset"],
|
||||
xAdvance: charObj["xadvance"]
|
||||
};
|
||||
}
|
||||
|
||||
//kerning
|
||||
var kerningDict = fnt.kerningDict = {};
|
||||
var kerningLines = fntStr.match(self.KERNING_EXP);
|
||||
if (kerningLines) {
|
||||
for (i = 0, li = kerningLines.length; i < li; i++) {
|
||||
var kerningObj = self._parseStrToObj(kerningLines[i]);
|
||||
kerningDict[(kerningObj["first"] << 16) | (kerningObj["second"] & 0xffff)] = kerningObj["amount"];
|
||||
}
|
||||
}
|
||||
return fnt;
|
||||
}
|
||||
};
|
||||
|
||||
var FontLetterDefinition = function() {
|
||||
this._u = 0;
|
||||
@@ -138,7 +224,7 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
_isUnderline: false,
|
||||
|
||||
//fontHandle it is a system font name, ttf file path or bmfont file path.
|
||||
ctor: function(string, fontHandle, textureUrl) {
|
||||
ctor: function(string, fontHandle, spriteFrame) {
|
||||
EventTarget.call(this);
|
||||
|
||||
fontHandle = fontHandle || "";
|
||||
@@ -154,7 +240,7 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
_ccsg.Node.prototype.setContentSize.call(this, cc.size(128, 128));
|
||||
this._blendFunc = cc.BlendFunc._alphaNonPremultiplied();
|
||||
|
||||
this.setFontFileOrFamily(fontHandle, textureUrl);
|
||||
this.setFontFileOrFamily(fontHandle, spriteFrame);
|
||||
this.setString(this._string);
|
||||
},
|
||||
|
||||
@@ -395,13 +481,13 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
}
|
||||
},
|
||||
|
||||
setFontFileOrFamily: function(fontHandle, textureUrl) {
|
||||
setFontFileOrFamily: function(fontHandle, spriteFrame) {
|
||||
fontHandle = fontHandle || "Arial";
|
||||
var extName = cc.path.extname(fontHandle);
|
||||
|
||||
this._resetBMFont();
|
||||
//specify font family name directly
|
||||
if (!extName) {
|
||||
if (!extName && !spriteFrame) {
|
||||
this._fontHandle = fontHandle;
|
||||
this._labelType = _ccsg.Label.Type.SystemFont;
|
||||
this._blendFunc = cc.BlendFunc._alphaPremultiplied();
|
||||
@@ -416,12 +502,12 @@ _ccsg.Label = _ccsg.Node.extend({
|
||||
this._blendFunc = cc.BlendFunc._alphaPremultiplied();
|
||||
this._renderCmd._needDraw = true;
|
||||
this._fontHandle = this._loadTTFFont(fontHandle);
|
||||
} else if (extName === ".fnt") {
|
||||
} else if (spriteFrame) {
|
||||
//todo add bmfont here
|
||||
this._labelType = _ccsg.Label.Type.BMFont;
|
||||
this._blendFunc = cc.BlendFunc._alphaNonPremultiplied();
|
||||
this._renderCmd._needDraw = false;
|
||||
this._initBMFontWithString(this._string, fontHandle, textureUrl);
|
||||
this._initBMFontWithString(this._string, fontHandle, spriteFrame);
|
||||
}
|
||||
this._notifyLabelSkinDirty();
|
||||
},
|
||||
@@ -638,14 +724,34 @@ cc.BMFontHelper = {
|
||||
if (this._reusedRect.height > 0 && this._reusedRect.width > 0) {
|
||||
var fontChar = this.getChildByTag(ctr);
|
||||
var locTexture = this._spriteBatchNode._texture;
|
||||
var spriteFrame = this._spriteFrame;
|
||||
|
||||
var isRotated = this._spriteFrame.isRotated();
|
||||
|
||||
var originalSize = spriteFrame._originalSize;
|
||||
var rect = spriteFrame._rect;
|
||||
var offset = spriteFrame._offset;
|
||||
var trimmedLeft = offset.x + (originalSize.width - rect.width) / 2;
|
||||
var trimmedTop = offset.y - (originalSize.height - rect.height) / 2;
|
||||
|
||||
|
||||
if(!isRotated) {
|
||||
this._reusedRect.x += (rect.x - trimmedLeft);
|
||||
this._reusedRect.y += (rect.y + trimmedTop);
|
||||
} else {
|
||||
var originalX = this._reusedRect.x;
|
||||
this._reusedRect.x = rect.x + rect.height - this._reusedRect.y - this._reusedRect.height - trimmedTop;
|
||||
this._reusedRect.y = originalX + rect.y - trimmedLeft;
|
||||
}
|
||||
|
||||
if (!fontChar) {
|
||||
fontChar = new _ccsg.Sprite();
|
||||
fontChar.initWithTexture(locTexture);
|
||||
fontChar.initWithTexture(locTexture, this._reusedRect, isRotated);
|
||||
fontChar.setAnchorPoint(cc.p(0, 1));
|
||||
} else {
|
||||
fontChar.setTextureRect(this._reusedRect, isRotated);
|
||||
}
|
||||
|
||||
fontChar.setTextureRect(this._reusedRect, false, this._reusedRect.size);
|
||||
|
||||
var letterPositionX = this._lettersInfo[ctr]._positionX + this._linesOffsetX[this._lettersInfo[ctr]._lineIndex];
|
||||
fontChar.setPosition(letterPositionX, py);
|
||||
@@ -1054,14 +1160,14 @@ cc.BMFontHelper = {
|
||||
|
||||
},
|
||||
|
||||
_initBMFontWithString: function(str, fntFile, textureUrl) {
|
||||
_initBMFontWithString: function(str, fntFile, spriteFrame) {
|
||||
var self = this;
|
||||
if (self._config) {
|
||||
cc.logID(4002);
|
||||
return false;
|
||||
}
|
||||
this._string = str;
|
||||
this._setBMFontFile(fntFile, textureUrl);
|
||||
this._setBMFontFile(fntFile, spriteFrame);
|
||||
},
|
||||
|
||||
_createSpriteBatchNode: function(texture) {
|
||||
@@ -1137,40 +1243,36 @@ cc.BMFontHelper = {
|
||||
}
|
||||
},
|
||||
|
||||
_setBMFontFile: function(filename, textureUrl) {
|
||||
if (filename) {
|
||||
this._fontHandle = filename;
|
||||
_setBMFontFile: function(fntDataStr, spriteFrame) {
|
||||
if (fntDataStr) {
|
||||
this._fontHandle = fntDataStr;
|
||||
if (this._labelType === _ccsg.Label.Type.BMFont) {
|
||||
var self = this;
|
||||
this._resetBMFont();
|
||||
|
||||
cc.loader.load(this._fontHandle, function(err, config) {
|
||||
if (err) {
|
||||
cc.logID(4001);
|
||||
}
|
||||
self._config = FntLoader.parseFnt(fntDataStr);
|
||||
self._createFontChars();
|
||||
var texture = spriteFrame.getTexture();
|
||||
self._spriteFrame = spriteFrame;
|
||||
|
||||
self._config = config;
|
||||
self._createFontChars();
|
||||
var texture = cc.textureCache.addImage(textureUrl || self._config.atlasName);
|
||||
var locIsLoaded = texture.isLoaded();
|
||||
self._textureLoaded = locIsLoaded;
|
||||
if (!locIsLoaded) {
|
||||
texture.once("load", function() {
|
||||
var self = this;
|
||||
var locIsLoaded = texture.isLoaded();
|
||||
self._textureLoaded = locIsLoaded;
|
||||
if (!locIsLoaded) {
|
||||
texture.once("load", function() {
|
||||
var self = this;
|
||||
|
||||
if (!self._spriteBatchNode) {
|
||||
self._createSpriteBatchNode(texture);
|
||||
}
|
||||
self._textureLoaded = true;
|
||||
self.emit("load");
|
||||
}, self);
|
||||
} else {
|
||||
if (!self._spriteBatchNode) {
|
||||
self._createSpriteBatchNode(texture);
|
||||
self.emit("load");
|
||||
}
|
||||
self._textureLoaded = true;
|
||||
self.emit("load");
|
||||
}, self);
|
||||
} else {
|
||||
if (!self._spriteBatchNode) {
|
||||
self._createSpriteBatchNode(texture);
|
||||
self.emit("load");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ _ccsg.Label.WebGLRenderCmd = function(renderableObject){
|
||||
this._color = new Uint32Array(1);
|
||||
this._dirty = false;
|
||||
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_SPRITE_POSITION_TEXTURECOLORALPHATEST);
|
||||
this._shaderProgram = cc.shaderCache.programForKey(cc.macro.SHADER_SPRITE_POSITION_TEXTURECOLOR);
|
||||
};
|
||||
|
||||
var proto = _ccsg.Label.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
|
||||
@@ -194,9 +194,9 @@ JS.mixin(CCLoader.prototype, {
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var singleRes = null;
|
||||
var singleRes = false;
|
||||
if (!(resources instanceof Array)) {
|
||||
singleRes = resources;
|
||||
singleRes = true;
|
||||
resources = resources ? [resources] : [];
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ JS.mixin(CCLoader.prototype, {
|
||||
return;
|
||||
|
||||
if (singleRes) {
|
||||
var id = singleRes.url || singleRes.uuid || singleRes;
|
||||
var id = res.url;
|
||||
completeCallback.call(self, items.getError(id), items.getContent(id));
|
||||
}
|
||||
else {
|
||||
@@ -311,16 +311,20 @@ JS.mixin(CCLoader.prototype, {
|
||||
// Find the asset's reference id in loader, asset could be asset object, asset uuid or asset url
|
||||
_getReferenceKey: function (assetOrUrlOrUuid) {
|
||||
var key;
|
||||
if (typeof assetOrUrlOrUuid === 'string') {
|
||||
key = this._getResUuid(assetOrUrlOrUuid) || assetOrUrlOrUuid;
|
||||
}
|
||||
else if (typeof assetOrUrlOrUuid === 'object') {
|
||||
if (typeof assetOrUrlOrUuid === 'object') {
|
||||
key = assetOrUrlOrUuid._uuid || null;
|
||||
}
|
||||
else if (typeof assetOrUrlOrUuid === 'string') {
|
||||
key = this._getResUuid(assetOrUrlOrUuid) || assetOrUrlOrUuid;
|
||||
}
|
||||
else if (CC_DEV) {
|
||||
cc.warnID(4800, assetOrUrlOrUuid);
|
||||
}
|
||||
key = cc.AssetLibrary._getAssetUrl(key) || key;
|
||||
var isUuid = cc.AssetLibrary._getAssetUrl(key);
|
||||
if (isUuid) {
|
||||
cc.AssetLibrary._getAssetInfoInRuntime(key, _info);
|
||||
key = _info.url;
|
||||
}
|
||||
return key;
|
||||
},
|
||||
|
||||
@@ -453,7 +457,8 @@ JS.mixin(CCLoader.prototype, {
|
||||
var results = [];
|
||||
for (var i = 0; i < res.length; ++i) {
|
||||
var uuid = res[i].uuid;
|
||||
var item = items.getContent(uuid);
|
||||
var id = this._getReferenceKey(uuid);
|
||||
var item = items.getContent(id);
|
||||
if (item) {
|
||||
// should not release these assets, even if they are static referenced in the scene.
|
||||
self.setAutoReleaseRecursively(uuid, false);
|
||||
|
||||
@@ -72,93 +72,6 @@ function loadPlist (item, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
var fntRE = {
|
||||
INFO_EXP: /info [^\n]*(\n|$)/gi,
|
||||
COMMON_EXP: /common [^\n]*(\n|$)/gi,
|
||||
PAGE_EXP: /page [^\n]*(\n|$)/gi,
|
||||
CHAR_EXP: /char [^\n]*(\n|$)/gi,
|
||||
KERNING_EXP: /kerning [^\n]*(\n|$)/gi,
|
||||
ITEM_EXP: /\w+=[^ \r\n]+/gi,
|
||||
INT_EXP: /^[\-]?\d+$/,
|
||||
};
|
||||
function _parseFntStrToObj (str) {
|
||||
var arr = str.match(fntRE.ITEM_EXP);
|
||||
var obj = {};
|
||||
if (arr) {
|
||||
for (var i = 0, li = arr.length; i < li; i++) {
|
||||
var tempStr = arr[i];
|
||||
var index = tempStr.indexOf('=');
|
||||
var key = tempStr.substring(0, index);
|
||||
var value = tempStr.substring(index + 1);
|
||||
if (value.match(fntRE.INT_EXP)) value = parseInt(value);
|
||||
else if (value[0] === '"') value = value.substring(1, value.length - 1);
|
||||
obj[key] = value;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
function loadFnt (item, callback) {
|
||||
var fntStr = item.content;
|
||||
var url = item.url;
|
||||
|
||||
var fnt = {}, i, li;
|
||||
//padding
|
||||
var infoObj = _parseFntStrToObj(fntStr.match(fntRE.INFO_EXP)[0]);
|
||||
var paddingArr = infoObj['padding'].split(',');
|
||||
var padding = {
|
||||
left: parseInt(paddingArr[0]),
|
||||
top: parseInt(paddingArr[1]),
|
||||
right: parseInt(paddingArr[2]),
|
||||
bottom: parseInt(paddingArr[3])
|
||||
};
|
||||
|
||||
//common
|
||||
var commonObj = _parseFntStrToObj(fntStr.match(fntRE.COMMON_EXP)[0]);
|
||||
fnt.commonHeight = commonObj['lineHeight'];
|
||||
//font size
|
||||
fnt.fontSize = infoObj['size'];
|
||||
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
|
||||
var texSize = cc.configuration.getMaxTextureSize();
|
||||
if (commonObj['scaleW'] > texSize.width || commonObj['scaleH'] > texSize.height) {
|
||||
cc.logID(4917);
|
||||
}
|
||||
}
|
||||
if (commonObj['pages'] !== 1) {
|
||||
cc.logID(4918);
|
||||
}
|
||||
|
||||
//page
|
||||
var pageObj = _parseFntStrToObj(fntStr.match(fntRE.PAGE_EXP)[0]);
|
||||
if (pageObj['id'] !== 0) {
|
||||
cc.logID(4919);
|
||||
}
|
||||
fnt.atlasName = cc.path.changeBasename(url, pageObj['file']);
|
||||
|
||||
//char
|
||||
var charLines = fntStr.match(fntRE.CHAR_EXP);
|
||||
var fontDefDictionary = fnt.fontDefDictionary = {};
|
||||
for (i = 0, li = charLines.length; i < li; i++) {
|
||||
var charObj = _parseFntStrToObj(charLines[i]);
|
||||
var charId = charObj['id'];
|
||||
fontDefDictionary[charId] = {
|
||||
rect: {x: charObj['x'], y: charObj['y'], width: charObj['width'], height: charObj['height']},
|
||||
xOffset: charObj['xoffset'],
|
||||
yOffset: charObj['yoffset'],
|
||||
xAdvance: charObj['xadvance']
|
||||
};
|
||||
}
|
||||
|
||||
//kerning
|
||||
var kerningDict = fnt.kerningDict = {};
|
||||
var kerningLines = fntStr.match(fntRE.KERNING_EXP);
|
||||
if (kerningLines) {
|
||||
for (i = 0, li = kerningLines.length; i < li; i++) {
|
||||
var kerningObj = _parseFntStrToObj(kerningLines[i]);
|
||||
kerningDict[(kerningObj['first'] << 16) | (kerningObj['second'] & 0xffff)] = kerningObj['amount'];
|
||||
}
|
||||
}
|
||||
callback(null, fnt);
|
||||
}
|
||||
|
||||
var defaultMap = {
|
||||
// Images
|
||||
@@ -177,7 +90,8 @@ var defaultMap = {
|
||||
|
||||
'plist' : loadPlist,
|
||||
|
||||
'fnt' : loadFnt,
|
||||
// we embed fnt data inside the asset json file
|
||||
// 'fnt' : loadFnt,
|
||||
|
||||
'uuid' : loadUuid,
|
||||
'prefab' : loadUuid,
|
||||
@@ -208,7 +122,7 @@ var ID = 'Loader';
|
||||
* // This will match all url with `.scene` extension or all url with `scene` type
|
||||
* 'scene' : function (url, callback) {}
|
||||
* });
|
||||
*
|
||||
*
|
||||
* @method Loader
|
||||
* @param {Object} extMap Custom supported types with corresponded handler
|
||||
*/
|
||||
@@ -243,4 +157,4 @@ JS.mixin(Loader.prototype, {
|
||||
}
|
||||
});
|
||||
|
||||
Pipeline.Loader = module.exports = Loader;
|
||||
Pipeline.Loader = module.exports = Loader;
|
||||
|
||||
@@ -39,7 +39,7 @@ _ccsg.Sprite.WebGLRenderCmd = function (renderable) {
|
||||
this._dirty = false;
|
||||
this._recursiveDirty = false;
|
||||
|
||||
this._shaderProgram = cc.shaderCache.programForKey(macro.SHADER_SPRITE_POSITION_TEXTURECOLORALPHATEST);
|
||||
this._shaderProgram = cc.shaderCache.programForKey(macro.SHADER_SPRITE_POSITION_TEXTURECOLOR);
|
||||
};
|
||||
|
||||
var proto = _ccsg.Sprite.WebGLRenderCmd.prototype = Object.create(_ccsg.Node.WebGLRenderCmd.prototype);
|
||||
|
||||
@@ -279,7 +279,7 @@ dragonBones.ArmatureDisplay = cc.Class({
|
||||
|
||||
// IMPLEMENT
|
||||
ctor : function () {
|
||||
this._factory = new dragonBones.CCFactory();
|
||||
this._factory = dragonBones.CCFactory.getFactory();
|
||||
},
|
||||
|
||||
__preload : function () {
|
||||
|
||||
@@ -92,6 +92,14 @@ dragonBones.CCArmatureDisplay = cc.Class({
|
||||
this.off(type, listener, target);
|
||||
},
|
||||
|
||||
dispose : function() {
|
||||
if (this._armature) {
|
||||
this.advanceTimeBySelf(false);
|
||||
this._armature.dispose();
|
||||
this._armature = null;
|
||||
}
|
||||
},
|
||||
|
||||
armature : function() {
|
||||
return this._armature;
|
||||
},
|
||||
|
||||
@@ -70,8 +70,10 @@ dragonBones.CCFactory = cc.Class({
|
||||
var displayList = [];
|
||||
|
||||
slot.name = slotData.name;
|
||||
slot._rawDisplay = new _ccsg.Sprite();
|
||||
slot._meshDisplay = new cc.Scale9Sprite();
|
||||
slot._rawDisplay = new cc.Scale9Sprite();
|
||||
slot._rawDisplay.setRenderingType(cc.Scale9Sprite.RenderingType.SIMPLE); // use simple rendering type as default
|
||||
slot._rawDisplay.setAnchorPoint(cc.p(0,0));
|
||||
slot._meshDisplay = slot._rawDisplay;
|
||||
|
||||
for (var i = 0, l = slotDisplayDataSet.displays.length; i < l; ++i) {
|
||||
var displayData = slotDisplayDataSet.displays[i];
|
||||
@@ -125,8 +127,35 @@ dragonBones.CCFactory = cc.Class({
|
||||
|
||||
slot._setDisplayList(displayList);
|
||||
slot._rawDisplay.setLocalZOrder(slotData.zOrder);
|
||||
slot._meshDisplay.setLocalZOrder(slotData.zOrder);
|
||||
|
||||
return slot;
|
||||
},
|
||||
|
||||
getTextureDisplay: function(textureName, textureAtlasName) {
|
||||
var textureData = this._getTextureData(textureAtlasName, textureName);
|
||||
if (textureData) {
|
||||
if (!textureData.texture) {
|
||||
var textureAtlasTexture = textureData.parent.texture;
|
||||
var rect = cc.rect(textureData.region.x, textureData.region.y, textureData.region.width, textureData.region.height);
|
||||
var offset = cc.p(0, 0);
|
||||
var originSize = cc.size(textureData.region.width, textureData.region.height);
|
||||
textureData.texture = new cc.SpriteFrame();
|
||||
textureData.texture.setTexture(textureAtlasTexture, rect, textureData.rotated, offset, originSize); // TODO multiply textureAtlas
|
||||
}
|
||||
|
||||
var ret = new _ccsg.Sprite();
|
||||
ret.initWithSpriteFrame(textureData.texture);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
dragonBones.CCFactory._factory = null;
|
||||
dragonBones.CCFactory.getFactory = function() {
|
||||
if (!dragonBones.CCFactory._factory) {
|
||||
dragonBones.CCFactory._factory = new dragonBones.CCFactory();
|
||||
}
|
||||
return dragonBones.CCFactory._factory;
|
||||
};
|
||||
|
||||
@@ -75,12 +75,12 @@ dragonBones.CCSlot = cc.Class({
|
||||
},
|
||||
|
||||
_updateBlendMode : function () {
|
||||
if (this._renderDisplay instanceof _ccsg.Sprite) {
|
||||
if (this._renderDisplay instanceof cc.Scale9Sprite) {
|
||||
switch (this._blendMode) {
|
||||
case 0: // BlendMode Normal
|
||||
break;
|
||||
case 1: // BlendMode Add
|
||||
var texture = this._renderDisplay.getTexture();
|
||||
var texture = this._renderDisplay._spriteFrame.getTexture();
|
||||
if (texture && texture.hasPremultipliedAlpha()) {
|
||||
this._renderDisplay.setBlendFunc(cc.BlendFunc.BlendFactor.ONE, cc.BlendFunc.BlendFactor.ONE);
|
||||
}
|
||||
@@ -204,23 +204,25 @@ dragonBones.CCSlot = cc.Class({
|
||||
this._meshDisplay.setAnchorPoint(cc.p(0, 0));
|
||||
}
|
||||
else {
|
||||
var scale = this._armature.armatureData.scale;
|
||||
var pivot = cc.p(currentDisplayData.pivot.x, currentDisplayData.pivot.y);
|
||||
var rectData = currentTextureData.frame || currentTextureData.region;
|
||||
var width = rectData.width;
|
||||
var height = rectData.height;
|
||||
if (!currentTextureData.frame && currentTextureData.rotated) {
|
||||
width = rectData.height;
|
||||
height = rectData.width;
|
||||
}
|
||||
|
||||
if (currentDisplayData.isRelativePivot) {
|
||||
var rectData = currentTextureData.frame || currentTextureData.region;
|
||||
var width = rectData.width * scale;
|
||||
var height = rectData.height * scale;
|
||||
if (!currentTextureData.frame && currentTextureData.rotated) {
|
||||
width = rectData.height;
|
||||
height = rectData.width;
|
||||
}
|
||||
|
||||
pivot.x *= width;
|
||||
pivot.y *= height;
|
||||
}
|
||||
|
||||
if (currentTextureData.frame) {
|
||||
pivot.x += currentTextureData.frame.x;
|
||||
pivot.y += currentTextureData.frame.y;
|
||||
pivot.x += currentTextureData.frame.x * scale;
|
||||
pivot.y += currentTextureData.frame.y * scale;
|
||||
}
|
||||
|
||||
if (rawDisplayData && rawDisplayData !== currentDisplayData) {
|
||||
@@ -236,6 +238,7 @@ dragonBones.CCSlot = cc.Class({
|
||||
this._rawDisplay.setTexture(currentTexture);
|
||||
}
|
||||
this._rawDisplay.setAnchorPoint(pivot);
|
||||
this._blendModeDirty = true;
|
||||
}
|
||||
|
||||
this._updateVisible();
|
||||
@@ -245,7 +248,6 @@ dragonBones.CCSlot = cc.Class({
|
||||
}
|
||||
|
||||
this._rawDisplay.setTexture(null);
|
||||
this._rawDisplay.setTextureRect(cc.rect(0, 0, 0, 0));
|
||||
this._rawDisplay.setAnchorPoint(cc.p(0, 0));
|
||||
this._rawDisplay.setVisible(false);
|
||||
},
|
||||
|
||||
+2330
-1464
File diff suppressed because it is too large
Load Diff
@@ -153,7 +153,7 @@ sp._SGSkeleton = _ccsg.Node.extend({
|
||||
for (var i = 0, slotCount = slots.length; i < slotCount; ++i) {
|
||||
var slot = slots[i];
|
||||
var attachment = slot.attachment;
|
||||
if (!attachment || ! attachment instanceof spine.RegionAttachment)
|
||||
if (!attachment || !(attachment instanceof spine.RegionAttachment))
|
||||
continue;
|
||||
vertices = attachment.updateWorldVertices(slot, false);
|
||||
minX = Math.min(minX, vertices[VERTEX.X1] * scaleX, vertices[VERTEX.X4] * scaleX, vertices[VERTEX.X2] * scaleX, vertices[VERTEX.X3] * scaleX);
|
||||
|
||||
+7
-7
@@ -149,11 +149,11 @@ jsbLabel.prototype.setContentSize = function (size, height) {
|
||||
};
|
||||
|
||||
|
||||
jsbLabel.prototype.setFontFileOrFamily = function (fontHandle) {
|
||||
jsbLabel.prototype.setFontFileOrFamily = function (fontHandle, spriteFrame) {
|
||||
fontHandle = fontHandle || '';
|
||||
var extName = cc.path.extname(fontHandle);
|
||||
//specify font family name directly
|
||||
if (!extName) {
|
||||
if (!extName && !spriteFrame) {
|
||||
this._labelType = _ccsg.Label.Type.SystemFont;
|
||||
this.setSystemFontName(fontHandle);
|
||||
this._isSystemFontUsed = true;
|
||||
@@ -173,9 +173,9 @@ jsbLabel.prototype.setFontFileOrFamily = function (fontHandle) {
|
||||
this._labelType = _ccsg.Label.Type.TTF;
|
||||
this._ttfConfig.fontFilePath = fontHandle;
|
||||
this.setTTFConfig(this._ttfConfig);
|
||||
} else if (extName === '.fnt') {
|
||||
} else if (spriteFrame) {
|
||||
this._labelType = _ccsg.Label.Type.BMFont;
|
||||
this.setBMFontFilePath(fontHandle);
|
||||
this.setBMFontFilePath(fontHandle, spriteFrame);
|
||||
this.setFontSize(this.getFontSize());
|
||||
}
|
||||
}
|
||||
@@ -224,7 +224,7 @@ jsbLabel.prototype.getOutlineColor = function() {
|
||||
};
|
||||
|
||||
|
||||
cc.Label = function (string, fontHandle) {
|
||||
cc.Label = function (string, fontHandle, spriteFrame) {
|
||||
fontHandle = fontHandle || "Arial";
|
||||
var extName = cc.path.extname(fontHandle);
|
||||
|
||||
@@ -243,8 +243,8 @@ cc.Label = function (string, fontHandle) {
|
||||
label = jsbLabel.createWithTTF(ttfConfig, string, 40);
|
||||
label._ttfConfig = ttfConfig;
|
||||
}
|
||||
else if (extName === ".fnt") {
|
||||
label = jsbLabel.createWithBMFont(fontHandle, string);
|
||||
else if (spriteFrame) {
|
||||
label = jsbLabel.createWithBMFont(fontHandle, string, spriteFrame);
|
||||
type = _ccsg.Label.Type.BMFont;
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user