mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
@@ -126,7 +126,7 @@ cc.ActionInterval = cc.FiniteTimeAction.extend({
|
||||
* @param {Object} easeObj
|
||||
* @returns {ActionInterval}
|
||||
* @example
|
||||
* action.easeing(cc.easeIn(3.0));
|
||||
* action.easing(cc.easeIn(3.0));
|
||||
*/
|
||||
easing: function (easeObj) {
|
||||
if (this._easeList)
|
||||
|
||||
@@ -144,7 +144,6 @@ Audio.State = {
|
||||
this._state = Audio.State.PLAYING;
|
||||
|
||||
if (this._audioType === Audio.Type.DOM && this._element.paused) {
|
||||
this.stop();
|
||||
touchPlayList.push({ instance: this, offset: 0, audio: this._element });
|
||||
}
|
||||
|
||||
|
||||
@@ -1417,7 +1417,7 @@ var Node = cc.Class({
|
||||
cc.log(cc._LogInfos.Node.getActionByTag);
|
||||
return null;
|
||||
}
|
||||
cc.director.getActionManager().getActionByTag(tag, this);
|
||||
return cc.director.getActionManager().getActionByTag(tag, this);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1439,7 +1439,7 @@ var Node = cc.Class({
|
||||
* cc.log("Running Action Count: " + count);
|
||||
*/
|
||||
getNumberOfRunningActions: function () {
|
||||
cc.director.getActionManager().numberOfRunningActionsInTarget(this);
|
||||
return cc.director.getActionManager().getNumberOfRunningActionsInTarget(this);
|
||||
},
|
||||
|
||||
_retainAction: function (action) {
|
||||
|
||||
@@ -1492,7 +1492,7 @@ _ccsg.Node = cc.Class({
|
||||
* @return {Number} The number of actions that are running plus the ones that are schedule to run
|
||||
*/
|
||||
getNumberOfRunningActions: function () {
|
||||
return this.actionManager.numberOfRunningActionsInTarget(this);
|
||||
return this.actionManager.getNumberOfRunningActionsInTarget(this);
|
||||
},
|
||||
|
||||
// _ccsg.Node - Callbacks
|
||||
|
||||
@@ -319,11 +319,12 @@ var CollisionManager = cc.Class({
|
||||
},
|
||||
|
||||
drawColliders: function () {
|
||||
if (!this._enabledDebugDraw || !this._debugDrawer) {
|
||||
var debugDrawer = this._debugDrawer;
|
||||
if (!this._enabledDebugDraw || !debugDrawer) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._debugDrawer.clear();
|
||||
debugDrawer.clear();
|
||||
|
||||
var colliders = this._colliders;
|
||||
|
||||
@@ -331,16 +332,35 @@ var CollisionManager = cc.Class({
|
||||
var collider = colliders[i];
|
||||
|
||||
if (collider instanceof cc.BoxCollider || collider instanceof cc.PolygonCollider) {
|
||||
this._debugDrawer.drawPoly(collider.world.points.concat(), null, 1, cc.Color.WHITE);
|
||||
var ps = collider.world.points;
|
||||
if (ps.length > 0) {
|
||||
debugDrawer.strokeColor = cc.Color.WHITE;
|
||||
debugDrawer.moveTo(ps[0].x, ps[0].y);
|
||||
for (var j = 1; j < ps.length; j++) {
|
||||
debugDrawer.lineTo(ps[j].x, ps[j].y);
|
||||
}
|
||||
debugDrawer.close();
|
||||
debugDrawer.stroke();
|
||||
}
|
||||
}
|
||||
else if (collider instanceof cc.CircleCollider) {
|
||||
this._debugDrawer.drawCircle(collider.world.position, collider.world.radius, 0, 30);
|
||||
debugDrawer.circle(collider.world.position.x, collider.world.position.y, collider.world.radius);
|
||||
debugDrawer.stroke();
|
||||
}
|
||||
|
||||
if (this.enabledDrawBoundingBox) {
|
||||
var aabb = collider.world.aabb;
|
||||
var points = [cc.v2(aabb.xMin, aabb.yMin), cc.v2(aabb.xMin, aabb.yMax), cc.v2(aabb.xMax, aabb.yMax), cc.v2(aabb.xMax, aabb.yMin)];
|
||||
this._debugDrawer.drawPoly(points, null, 1, cc.Color.BLUE);
|
||||
var ps = [cc.v2(aabb.xMin, aabb.yMin), cc.v2(aabb.xMin, aabb.yMax), cc.v2(aabb.xMax, aabb.yMax), cc.v2(aabb.xMax, aabb.yMin)];
|
||||
|
||||
if (ps.length > 0) {
|
||||
debugDrawer.strokeColor = cc.Color.BLUE;
|
||||
debugDrawer.moveTo(ps[0].x, ps[0].y);
|
||||
for (var j = 1; j < ps.length; j++) {
|
||||
debugDrawer.lineTo(ps[j].x, ps[j].y);
|
||||
}
|
||||
debugDrawer.close();
|
||||
debugDrawer.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -367,7 +387,7 @@ cc.js.getset(CollisionManager.prototype, 'enabledDebugDraw',
|
||||
function (value) {
|
||||
if (value && !this._enabledDebugDraw) {
|
||||
if (!this._debugDrawer) {
|
||||
this._debugDrawer = new cc.DrawNode();
|
||||
this._debugDrawer = new _ccsg.GraphicsNode();
|
||||
this._debugDrawer.retain();
|
||||
}
|
||||
|
||||
|
||||
@@ -504,17 +504,9 @@ var Label = cc.Class({
|
||||
_updateNodeSize: function () {
|
||||
var initialized = this._sgNode && this._sgNode.parent;
|
||||
if (initialized) {
|
||||
if (this.overflow === Overflow.NONE) {
|
||||
if (this.overflow === Overflow.NONE || this.overflow === Overflow.RESIZE_HEIGHT) {
|
||||
this.node.setContentSize(this._sgNode.getContentSize());
|
||||
}
|
||||
|
||||
if(this.overflow === Overflow.RESIZE_HEIGHT) {
|
||||
//call this.node.getContentSize actually sync the node size with sgNode
|
||||
//such that it won't trigger setDimensions method in jsb
|
||||
var originalSize = this.node.getContentSize();
|
||||
var newSize = this._sgNode.getContentSize();
|
||||
this.node.setContentSize(cc.size(originalSize.width, newSize.height));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -272,8 +272,7 @@ var Layout = cc.Class({
|
||||
},
|
||||
|
||||
_N$padding: {
|
||||
default: 0,
|
||||
editorOnly: true
|
||||
default: 0
|
||||
},
|
||||
/**
|
||||
* !#en The left padding of layout, it only effect the layout in one direction.
|
||||
@@ -415,10 +414,8 @@ var Layout = cc.Class({
|
||||
this.node.setContentSize(this._layoutSize);
|
||||
}
|
||||
|
||||
if(CC_EDITOR) {
|
||||
if(this._N$padding !== 0) {
|
||||
this._migratePaddingData();
|
||||
}
|
||||
if(this._N$padding !== 0) {
|
||||
this._migratePaddingData();
|
||||
}
|
||||
|
||||
this.node.on('size-changed', this._resized, this);
|
||||
|
||||
@@ -23,8 +23,25 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
// 快速滑动的临界值
|
||||
var _CUSTOMSCROLLTHRESHOLD = 200;
|
||||
/**
|
||||
* !#en The Page View Size Mode
|
||||
* !#zh 页面视图每个页面统一的大小类型
|
||||
* @enum PageView.SizeMode
|
||||
*/
|
||||
var SizeMode = cc.Enum({
|
||||
/**
|
||||
* !#en Each page is unified in size
|
||||
* !#zh 每个页面统一大小
|
||||
* @property {Number} Unified
|
||||
*/
|
||||
Unified: 0,
|
||||
/**
|
||||
* !#en Each page is in free size
|
||||
* !#zh 每个页面大小随意
|
||||
* @property {Number} Free
|
||||
*/
|
||||
Free: 1
|
||||
});
|
||||
|
||||
/**
|
||||
* !#en The Page View Direction
|
||||
@@ -82,9 +99,26 @@ var PageView = cc.Class({
|
||||
this._curPageIdx = 0;
|
||||
this._lastPageIdx = 0;
|
||||
this._pages = [];
|
||||
this._scrollCenterOffsetX = []; // 每一个页面居中时需要的偏移量(X)
|
||||
this._scrollCenterOffsetY = []; // 每一个页面居中时需要的偏移量(Y)
|
||||
},
|
||||
|
||||
properties: {
|
||||
|
||||
/**
|
||||
* !#en Specify the size type of each page in PageView.
|
||||
* !#zh 页面视图中每个页面大小类型
|
||||
* @property {PageView.SizeMode} sizeMode
|
||||
*/
|
||||
sizeMode: {
|
||||
default: SizeMode.Unified,
|
||||
type: SizeMode,
|
||||
tooltip: 'i18n:COMPONENT.pageview.sizeMode',
|
||||
notify: function() {
|
||||
this._syncSizeMode();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en The page view direction
|
||||
* !#zh 页面视图滚动类型
|
||||
@@ -114,6 +148,23 @@ var PageView = cc.Class({
|
||||
tooltip: 'i18n:COMPONENT.pageview.scrollThreshold'
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Auto page turning velocity threshold. When users swipe the PageView quickly,
|
||||
* it will calculate a velocity based on the scroll distance and time,
|
||||
* if the calculated velocity is larger than the threshold, then it will trigger page turning.
|
||||
* !#zh
|
||||
* 快速滑动翻页临界值。
|
||||
* 当用户快速滑动时,会根据滑动开始和结束的距离与时间计算出一个速度值,
|
||||
* 该值与此临界值相比较,如果大于临界值,则进行自动翻页。
|
||||
* @property {Number} autoPageTurningThreshold
|
||||
*/
|
||||
autoPageTurningThreshold: {
|
||||
default: 100,
|
||||
type: cc.Float,
|
||||
tooltip: 'i18n:COMPONENT.pageview.autoPageTurningThreshold'
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Change the PageTurning event timing of PageView.
|
||||
* !#zh 设置 PageView PageTurning 事件的发送时机。
|
||||
@@ -155,6 +206,7 @@ var PageView = cc.Class({
|
||||
},
|
||||
|
||||
statics: {
|
||||
SizeMode: SizeMode,
|
||||
Direction: Direction,
|
||||
EventType: EventType
|
||||
},
|
||||
@@ -162,12 +214,6 @@ var PageView = cc.Class({
|
||||
__preload: function () {
|
||||
this._super();
|
||||
this.node.on('size-changed', this._updateAllPagesSize, this);
|
||||
this._syncScrollDirection();
|
||||
},
|
||||
|
||||
_syncScrollDirection: function () {
|
||||
this.horizontal = this.direction === Direction.Horizontal;
|
||||
this.vertical = this.direction === Direction.Vertical;
|
||||
},
|
||||
|
||||
onEnable: function () {
|
||||
@@ -329,6 +375,35 @@ var PageView = cc.Class({
|
||||
return this.pageTurningEventTiming;
|
||||
},
|
||||
|
||||
_syncScrollDirection: function () {
|
||||
this.horizontal = this.direction === Direction.Horizontal;
|
||||
this.vertical = this.direction === Direction.Vertical;
|
||||
},
|
||||
|
||||
_syncSizeMode: function () {
|
||||
if (!this.content) { return; }
|
||||
var layout = this.content.getComponent(cc.Layout);
|
||||
if (layout) {
|
||||
if (this._pages.length === 0) {
|
||||
layout.padding = 0;
|
||||
}
|
||||
else {
|
||||
var lastPage = this._pages[this._pages.length - 1];
|
||||
if (this.sizeMode === SizeMode.Free) {
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
layout.paddingLeft = (this.node.width - this._pages[0].width) / 2;
|
||||
layout.paddingRight = (this.node.width - lastPage.width) / 2;
|
||||
}
|
||||
else if (this.direction === Direction.Vertical) {
|
||||
layout.paddingTop = (this.node.height - this._pages[0].height) / 2;
|
||||
layout.paddingBottom = (this.node.height - lastPage.height) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
layout._updateLayout();
|
||||
}
|
||||
},
|
||||
|
||||
// 刷新页面视图
|
||||
_updatePageView: function () {
|
||||
var pageCount = this._pages.length;
|
||||
@@ -345,6 +420,12 @@ var PageView = cc.Class({
|
||||
// 进行排序
|
||||
for (var i = 0; i < pageCount; ++i) {
|
||||
this._pages[i].setSiblingIndex(i);
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
this._scrollCenterOffsetX[i] = Math.abs(this.content.x + this._pages[i].x);
|
||||
}
|
||||
else {
|
||||
this._scrollCenterOffsetY[i] = Math.abs(this.content.y + this._pages[i].y);
|
||||
}
|
||||
}
|
||||
// 刷新 indicator 信息与状态
|
||||
if (this.indicator) {
|
||||
@@ -354,6 +435,9 @@ var PageView = cc.Class({
|
||||
|
||||
// 刷新所有页面的大小
|
||||
_updateAllPagesSize: function () {
|
||||
if (this.sizeMode !== SizeMode.Unified) {
|
||||
return;
|
||||
}
|
||||
var locPages = CC_EDITOR ? this.content.children : this._pages;
|
||||
var selfSize = this.node.getContentSize();
|
||||
for (var i = 0, len = locPages.length; i < len; i++) {
|
||||
@@ -370,6 +454,9 @@ var PageView = cc.Class({
|
||||
if (this._pages.indexOf(page) >= 0) { continue; }
|
||||
this._pages.push(page);
|
||||
}
|
||||
this._syncScrollDirection();
|
||||
this._syncSizeMode();
|
||||
this._updatePageView();
|
||||
},
|
||||
|
||||
_dispatchPageTurningEvent: function () {
|
||||
@@ -380,79 +467,126 @@ var PageView = cc.Class({
|
||||
},
|
||||
|
||||
// 是否超过自动滚动临界值
|
||||
_isScrollable: function (offset) {
|
||||
_isScrollable: function (offset, index, nextIndex) {
|
||||
if (this.sizeMode === SizeMode.Free) {
|
||||
var curPageCenter, nextPageCenter;
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
curPageCenter = this._scrollCenterOffsetX[index];
|
||||
nextPageCenter = this._scrollCenterOffsetX[nextIndex];
|
||||
return Math.abs(offset.x) >= Math.abs(curPageCenter - nextPageCenter) * this.scrollThreshold;
|
||||
}
|
||||
else if (this.direction === Direction.Vertical) {
|
||||
curPageCenter = this._scrollCenterOffsetY[index];
|
||||
nextPageCenter = this._scrollCenterOffsetY[nextIndex];
|
||||
return Math.abs(offset.y) >= Math.abs(curPageCenter - nextPageCenter) * this.scrollThreshold;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
return Math.abs(offset.x) >= this.node.width * this.scrollThreshold;
|
||||
}
|
||||
else if (this.direction === Direction.Vertical) {
|
||||
return Math.abs(offset.y) >= this.node.height * this.scrollThreshold;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 快速滑动
|
||||
_isQuicklyScrollable: function (touchMoveVelocity) {
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
return Math.abs(offset.x) >= this.node.width * this.scrollThreshold;
|
||||
if (Math.abs(touchMoveVelocity.x) > this.autoPageTurningThreshold) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (this.direction === Direction.Vertical) {
|
||||
return Math.abs(offset.y) >= this.node.height * this.scrollThreshold;
|
||||
if (Math.abs(touchMoveVelocity.y) > this.autoPageTurningThreshold) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// 通过 idx 获取偏移值数值
|
||||
_moveOffsetValue: function (idx) {
|
||||
var offset = cc.p(0, 0);
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
offset.x = idx * this.node.width;
|
||||
if (this.sizeMode === SizeMode.Free) {
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
offset.x = this._scrollCenterOffsetX[idx];
|
||||
}
|
||||
else if (this.direction === Direction.Vertical) {
|
||||
offset.y = this._scrollCenterOffsetY[idx];
|
||||
}
|
||||
}
|
||||
else if (this.direction === Direction.Vertical) {
|
||||
offset.y = idx * this.node.height;
|
||||
else {
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
offset.x = idx * this.node.width;
|
||||
}
|
||||
else if (this.direction === Direction.Vertical) {
|
||||
offset.y = idx * this.node.height;
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
},
|
||||
|
||||
_updatePageIndex: function (moveOffset) {
|
||||
var idx = 0;
|
||||
_getDragDirection: function (moveOffset) {
|
||||
if (this.direction === Direction.Horizontal) {
|
||||
idx += (moveOffset.x > 0 ? 1 : -1);
|
||||
return (moveOffset.x > 0 ? 1 : -1);
|
||||
}
|
||||
else if (this.direction === Direction.Vertical) {
|
||||
// 由于滚动 Y 轴的原点在在右上角所以应该是小于 0
|
||||
idx += (moveOffset.y < 0 ? 1 : -1);
|
||||
return (moveOffset.y < 0 ? 1 : -1);
|
||||
}
|
||||
return this._curPageIdx + idx;
|
||||
},
|
||||
|
||||
_handleReleaseLogic: function(touch) {
|
||||
var bounceBackStarted = this._startBounceBackIfNeeded();
|
||||
if (!bounceBackStarted) {
|
||||
var idx = this._curPageIdx;
|
||||
if (idx === 0 && this._pages.length === 1) {
|
||||
return;
|
||||
}
|
||||
var moveOffset = cc.pSub(this._touchBeganPosition, this._touchEndPosition);
|
||||
if (this._isScrollable(moveOffset)) {
|
||||
idx = this._updatePageIndex(moveOffset);
|
||||
var index = this._curPageIdx, nextIndex = 0;
|
||||
var moveOffset = cc.pSub(this._touchBeganPosition, this._touchEndPosition);
|
||||
if (bounceBackStarted) {
|
||||
if (this._getDragDirection(moveOffset) > 0) {
|
||||
this._curPageIdx = this._pages.length - 1;
|
||||
}
|
||||
else {
|
||||
var touchMoveVelocity = this._calculateTouchMoveVelocity();
|
||||
if (Math.abs(touchMoveVelocity.x) > _CUSTOMSCROLLTHRESHOLD) {
|
||||
idx = this._updatePageIndex(moveOffset);
|
||||
this._curPageIdx = 0;
|
||||
}
|
||||
if (this.indicator) {
|
||||
this.indicator._changedState();
|
||||
}
|
||||
}
|
||||
else {
|
||||
nextIndex = index + this._getDragDirection(moveOffset);
|
||||
if (nextIndex < this._pages.length) {
|
||||
if (this._isScrollable(moveOffset, index, nextIndex)) {
|
||||
this.scrollToPage(nextIndex);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
var touchMoveVelocity = this._calculateTouchMoveVelocity();
|
||||
if (this._isQuicklyScrollable(touchMoveVelocity)) {
|
||||
this.scrollToPage(nextIndex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.scrollToPage(idx);
|
||||
this.scrollToPage(index);
|
||||
}
|
||||
},
|
||||
|
||||
_onTouchBegan: function (event, captureListeners) {
|
||||
|
||||
this._touchBeganPosition = event.touch.getLocation();
|
||||
this._super(event, captureListeners);
|
||||
},
|
||||
|
||||
_onTouchMoved: function (event, captureListeners) {
|
||||
|
||||
this._super(event, captureListeners);
|
||||
},
|
||||
|
||||
_onTouchEnded: function (event, captureListeners) {
|
||||
|
||||
this._touchEndPosition = event.touch.getLocation();
|
||||
this._super(event, captureListeners);
|
||||
},
|
||||
|
||||
_onTouchCancelled: function (event, captureListeners) {
|
||||
|
||||
this._touchEndPosition = event.touch.getLocation();
|
||||
this._super(event, captureListeners);
|
||||
},
|
||||
|
||||
@@ -248,6 +248,9 @@ var RichText = cc.Class({
|
||||
},
|
||||
|
||||
_onTTFLoaded: function () {
|
||||
var rawUrl = this._getFontRawUrl();
|
||||
if(!rawUrl) return;
|
||||
|
||||
var self = this;
|
||||
|
||||
var callback = function () {
|
||||
@@ -255,7 +258,7 @@ var RichText = cc.Class({
|
||||
self._updateRichText();
|
||||
};
|
||||
|
||||
cc.CustomFontLoader.loadTTF(this._getFontRawUrl(), callback);
|
||||
cc.CustomFontLoader.loadTTF(rawUrl, callback);
|
||||
},
|
||||
|
||||
_measureText: function (styleIndex, string) {
|
||||
|
||||
@@ -538,7 +538,10 @@ var Sprite = cc.Class({
|
||||
|
||||
_onSpriteFrameLoaded: function (event) {
|
||||
var self = this;
|
||||
var sgNode = this._sgNode;
|
||||
if (!self.isValid) {
|
||||
return;
|
||||
}
|
||||
var sgNode = self._sgNode;
|
||||
sgNode.setSpriteFrame(self._spriteFrame);
|
||||
self._applyCapInset();
|
||||
self._applySpriteSize();
|
||||
|
||||
@@ -33,6 +33,14 @@ var CanvasRenderCmd = function (renderable) {
|
||||
_ccsg.Node.CanvasRenderCmd.call(this, renderable);
|
||||
this._needDraw = true;
|
||||
this.cmds = [];
|
||||
|
||||
this.style = {
|
||||
strokeStyle: 'black',
|
||||
fillStyle: 'white',
|
||||
lineCap: 'butt',
|
||||
lineJoin: 'miter',
|
||||
miterLimit: 10
|
||||
};
|
||||
};
|
||||
|
||||
var _p = CanvasRenderCmd.prototype = Object.create(_ccsg.Node.CanvasRenderCmd.prototype);
|
||||
@@ -52,6 +60,13 @@ _p.rendering = function (ctx, scaleX, scaleY) {
|
||||
context.save();
|
||||
context.scale(1, -1);
|
||||
|
||||
var style = this.style;
|
||||
context.strokeStyle = style.strokeStyle;
|
||||
context.fillStyle = style.fillStyle;
|
||||
context.lineWidth = style.lineWidth;
|
||||
context.lineJoin = style.lineJoin;
|
||||
context.miterLimit = style.miterLimit;
|
||||
|
||||
var endPath = true;
|
||||
var cmds = this.cmds;
|
||||
for (var i = 0, l = cmds.length; i < l; i++) {
|
||||
@@ -80,45 +95,56 @@ _p.rendering = function (ctx, scaleX, scaleY) {
|
||||
// draw api
|
||||
Js.mixin(_p, {
|
||||
setStrokeColor: function (v) {
|
||||
var fillStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
|
||||
this.cmds.push(['strokeStyle', fillStyle]);
|
||||
var strokeStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
|
||||
this.cmds.push(['strokeStyle', strokeStyle]);
|
||||
this.style.strokeStyle = strokeStyle;
|
||||
},
|
||||
|
||||
setFillColor: function (v) {
|
||||
var fillStyle = 'rgba(' + (0 | v.r) + ',' + (0 | v.g) + ',' + (0 | v.b) + ',' + v.a / 255 + ')';
|
||||
this.cmds.push(['fillStyle', fillStyle]);
|
||||
this.style.fillStyle = fillStyle;
|
||||
},
|
||||
|
||||
setLineWidth: function (v) {
|
||||
this.cmds.push(['lineWidth', v]);
|
||||
this.style.lineWidth = v;
|
||||
},
|
||||
|
||||
setLineCap: function (v) {
|
||||
var lineCap = 'butt';
|
||||
if (v === LineCap.BUTT) {
|
||||
this.cmds.push(['lineCap', 'butt']);
|
||||
lineCap = 'butt';
|
||||
}
|
||||
else if (v === LineCap.ROUND) {
|
||||
this.cmds.push(['lineCap', 'round']);
|
||||
lineCap = 'round';
|
||||
}
|
||||
else if (v === LineCap.SQUARE) {
|
||||
this.cmds.push(['lineCap', 'square']);
|
||||
lineCap = 'square';
|
||||
}
|
||||
this.cmds.push(['lineCap', lineCap]);
|
||||
this.style.lineCap = lineCap;
|
||||
},
|
||||
|
||||
setLineJoin: function (v) {
|
||||
var lineJoin = 'bevel';
|
||||
if (v === LineJoin.BEVEL) {
|
||||
this.cmds.push(['lineJoin', 'bevel']);
|
||||
lineJoin = 'bevel';
|
||||
}
|
||||
else if (v === LineJoin.ROUND) {
|
||||
this.cmds.push(['lineJoin', 'round']);
|
||||
lineJoin = 'round';
|
||||
}
|
||||
else if (v === LineJoin.MITER) {
|
||||
this.cmds.push(['lineJoin', 'miter']);
|
||||
lineJoin = 'miter';
|
||||
}
|
||||
|
||||
this.cmds.push(['lineJoin', lineJoin]);
|
||||
this.style.lineJoin = lineJoin;
|
||||
},
|
||||
|
||||
setMiterLimit: function (v) {
|
||||
this.cmds.push(['miterLimit', v]);
|
||||
this.style.miterLimit = v;
|
||||
},
|
||||
|
||||
// draw functions
|
||||
|
||||
@@ -27,6 +27,7 @@ var CustomFontDescriptor = function() {
|
||||
this._status = 'unloaded';
|
||||
//when font is loaded, it will notify each observer in the observers array
|
||||
this._observers = [];
|
||||
this._isLoadWithCSS = false;
|
||||
};
|
||||
|
||||
CustomFontDescriptor.prototype.onLoaded = function () {
|
||||
@@ -48,6 +49,10 @@ CustomFontDescriptor.prototype.addHandler = function (callback) {
|
||||
|
||||
var CustomFontLoader = {
|
||||
_fontCache: {},
|
||||
_fontWidthCache: {},
|
||||
_canvasContext: null,
|
||||
_testString: "BESbswy",
|
||||
_allFontsLoaded: false,
|
||||
loadTTF: function (url, callback) {
|
||||
//these platforms support window.FontFace, but it sucks sometimes.
|
||||
var useFontFace = (cc.sys.browserType !== cc.sys.BROWSER_TYPE_BAIDU
|
||||
@@ -59,6 +64,33 @@ var CustomFontLoader = {
|
||||
} else {
|
||||
this._loadWithCSS(url, callback);
|
||||
}
|
||||
|
||||
if(!cc.director.getScheduler().isScheduled(this._checkFontLoaded, this)) {
|
||||
cc.director.getScheduler().schedule(this._checkFontLoaded, this, 0.1);
|
||||
}
|
||||
},
|
||||
|
||||
_checkFontLoaded: function () {
|
||||
this._allFontsLoaded = true;
|
||||
|
||||
for(var k in this._fontCache) {
|
||||
var fontDescriptor = this._fontCache[k];
|
||||
if(fontDescriptor.isLoaded() || !fontDescriptor._isLoadWithCSS) {
|
||||
continue;
|
||||
}
|
||||
var oldWidth = this._fontWidthCache[k];
|
||||
this._canvasContext.font = '40px ' + k;
|
||||
var newWidth = this._canvasContext.measureText(this._testString).width;
|
||||
if(oldWidth !== newWidth) {
|
||||
fontDescriptor.onLoaded();
|
||||
} else {
|
||||
this._allFontsLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(this._allFontsLoaded) {
|
||||
cc.director.getScheduler().unschedule(this._checkFontLoaded, this);
|
||||
}
|
||||
},
|
||||
|
||||
_loadWithFontFace: function(url, callback) {
|
||||
@@ -116,12 +148,33 @@ var CustomFontLoader = {
|
||||
fontDescriptor = new CustomFontDescriptor();
|
||||
fontDescriptor.addHandler(callback);
|
||||
this._fontCache[fontFamilyName] = fontDescriptor;
|
||||
fontDescriptor._isLoadWithCSS = true;
|
||||
|
||||
if(!this._canvasContext) {
|
||||
var labelCanvas = document.createElement('canvas');
|
||||
labelCanvas.width = 100;
|
||||
labelCanvas.height = 100;
|
||||
this._canvasContext = labelCanvas.getContext('2d');
|
||||
}
|
||||
|
||||
var fontDesc = '40px ' + fontFamilyName;
|
||||
this._canvasContext.font = fontDesc;
|
||||
|
||||
var width = this._canvasContext.measureText(this._testString).width;
|
||||
this._fontWidthCache[fontFamilyName] = width;
|
||||
|
||||
var self = this;
|
||||
fontStyle.onload = function() {
|
||||
setTimeout(function () {
|
||||
fontDescriptor.onLoaded();
|
||||
}, 100);
|
||||
//in case some font won't cause the width as to system font.
|
||||
if(!self._allFontsLoaded) {
|
||||
cc.log("force notify all fonts loaded!");
|
||||
fontDescriptor.onLoaded();
|
||||
cc.director.getScheduler().unschedule(this._checkFontLoaded, this);
|
||||
}
|
||||
}, 20000);
|
||||
};
|
||||
|
||||
} else {
|
||||
if(!fontDescriptor.isLoaded()) {
|
||||
fontDescriptor.addHandler(callback);
|
||||
|
||||
@@ -38,6 +38,7 @@ function getXMLHttpRequest () {
|
||||
return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP');
|
||||
}
|
||||
|
||||
var _sharedResources = [];
|
||||
var _sharedList = [];
|
||||
|
||||
/**
|
||||
@@ -170,13 +171,17 @@ JS.mixin(CCLoader.prototype, {
|
||||
resources = resources ? [resources] : [];
|
||||
}
|
||||
|
||||
_sharedResources.length = resources.length;
|
||||
for (var i = 0; i < resources.length; ++i) {
|
||||
var url = resources[i].id || resources[i];
|
||||
if (typeof url !== 'string')
|
||||
continue;
|
||||
var item = this.getItem(url);
|
||||
if (item) {
|
||||
resources[i] = item;
|
||||
_sharedResources[i] = item;
|
||||
}
|
||||
else {
|
||||
_sharedResources[i] = resources[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +210,8 @@ JS.mixin(CCLoader.prototype, {
|
||||
});
|
||||
});
|
||||
LoadingItems.initQueueDeps(queue);
|
||||
queue.append(resources);
|
||||
queue.append(_sharedResources);
|
||||
_sharedResources.length = 0;
|
||||
},
|
||||
|
||||
flowInDeps: function (owner, urlList, callback) {
|
||||
|
||||
@@ -101,7 +101,8 @@ var properties = {
|
||||
}
|
||||
cc.engine.repaintInEditMode();
|
||||
},
|
||||
animatable: false
|
||||
animatable: false,
|
||||
tooltip: 'i18n:COMPONENT.particle_system.preview'
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -134,7 +135,8 @@ var properties = {
|
||||
}
|
||||
}
|
||||
},
|
||||
animatable: false
|
||||
animatable: false,
|
||||
tooltip: 'i18n:COMPONENT.particle_system.custom'
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -167,7 +169,8 @@ var properties = {
|
||||
}
|
||||
},
|
||||
animatable: false,
|
||||
url: cc.ParticleAsset
|
||||
url: cc.ParticleAsset,
|
||||
tooltip: 'i18n:COMPONENT.particle_system.file'
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -191,7 +194,8 @@ var properties = {
|
||||
this._applyFile();
|
||||
}
|
||||
},
|
||||
url: cc.Texture2D
|
||||
url: cc.Texture2D,
|
||||
tooltip: 'i18n:COMPONENT.particle_system.texture'
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -206,7 +210,8 @@ var properties = {
|
||||
set: function (value) {
|
||||
this._sgNode.particleCount = value;
|
||||
},
|
||||
visible: false
|
||||
visible: false,
|
||||
tooltip: 'i18n:COMPONENT.particle_system.particleCount'
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -226,7 +231,8 @@ var properties = {
|
||||
this._sgNode.setBlendFunc(this._blendFunc);
|
||||
},
|
||||
animatable: false,
|
||||
type:BlendFactor
|
||||
type:BlendFactor,
|
||||
tooltip: 'i18n:COMPONENT.particle_system.srcBlendFactor'
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -246,7 +252,8 @@ var properties = {
|
||||
this._sgNode.setBlendFunc(this._blendFunc);
|
||||
},
|
||||
animatable: false,
|
||||
type: BlendFactor
|
||||
type: BlendFactor,
|
||||
tooltip: 'i18n:COMPONENT.particle_system.dstBlendFactor'
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -276,7 +283,8 @@ var properties = {
|
||||
}
|
||||
}
|
||||
},
|
||||
animatable: false
|
||||
animatable: false,
|
||||
tooltip: 'i18n:COMPONENT.particle_system.autoRemoveOnFinish'
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -290,7 +290,7 @@ dragonBones.ArmatureDisplay = cc.Class({
|
||||
|
||||
_createSgNode: function () {
|
||||
if (this.dragonAsset && this.dragonAtlasAsset && this.armatureName) {
|
||||
return this._factory.buildArmatureDisplay(this.armatureName);
|
||||
return this._factory.buildArmatureDisplay(this.armatureName, this._dragonBonesData.name);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -311,10 +311,17 @@ dragonBones.ArmatureDisplay = cc.Class({
|
||||
|
||||
_parseDragonAsset : function() {
|
||||
if (this.dragonAsset) {
|
||||
var jsonObj = JSON.parse(this.dragonAsset.dragonBonesJson);
|
||||
var data = this._factory.getDragonBonesData(jsonObj.name);
|
||||
if (data) {
|
||||
// already added asset
|
||||
this._dragonBonesData = data;
|
||||
return;
|
||||
}
|
||||
|
||||
if (CC_JSB) {
|
||||
this._dragonBonesData = this._factory.parseDragonBonesData(this.dragonAsset.dragonBonesJson);
|
||||
} else {
|
||||
var jsonObj = JSON.parse(this.dragonAsset.dragonBonesJson);
|
||||
this._dragonBonesData = this._factory.parseDragonBonesData(jsonObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ jsbLabel.prototype.getTTFConfig = function () {
|
||||
return this._ttfConfig;
|
||||
};
|
||||
|
||||
jsbLabel.prototype._setContentSize = jsbLabel.prototype.setContentSize;
|
||||
jsbLabel.prototype.setContentSize = function (size, height) {
|
||||
var newWidth = (typeof size.width === 'number') ? size.width : size;
|
||||
var newHeight = (typeof size.height === 'number') ? size.height : height;
|
||||
@@ -141,6 +142,8 @@ jsbLabel.prototype.setContentSize = function (size, height) {
|
||||
if(this.getOverflow() === cc.Label.Overflow.NONE) {
|
||||
newWidth = 0;
|
||||
newHeight = 0;
|
||||
} else {
|
||||
this._setContentSize(newWidth, newHeight);
|
||||
}
|
||||
this.setDimensions(newWidth, newHeight);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user