Merge v2.0-release

# Conflicts:
#	predefine.js
This commit is contained in:
Jare Guo
2018-08-29 20:03:38 +08:00
55 changed files with 702 additions and 607 deletions
+4 -4
View File
@@ -234,7 +234,7 @@ cc.spriteFrameCache is removed, please use cc.loader to load and cache sprite fr
### 1405
The '%s' will be removed in v2.0, please use '%s' instead. 😥
The '%s' will be removed in v2.0, please use '%s' instead.
### 1406
@@ -1135,7 +1135,7 @@ Unknown editor property '%s' in class '%s'.
### 3603
Use 'cc.Float' or 'cc.Integer' instead of 'cc.Number' please. 😂
Use 'cc.Float' or 'cc.Integer' instead of 'cc.Number' please.
### 3604
@@ -1340,7 +1340,7 @@ Failed to construct a dummy instance of the "%s" class using `new` behind the sc
### 3653
Please do not specifiy "default" attribute in decorator of "%s" property in "%s" class.
Default value must be initialized at their declaration: 😰
Default value must be initialized at their declaration:
```
// Before:
@property({
@@ -1357,7 +1357,7 @@ value = 0; // <--
### 3654
Please specifiy a default value for "%s" property at its declaration: 😰
Please specifiy a default value for "%s" property at its declaration:
```
// Before:
@property(...)
+3 -1
View File
@@ -148,8 +148,10 @@ cc.ActionManager.prototype = {
for (var i = 0; i < locTargets.length; i++) {
var element = locTargets[i];
if (element)
this.removeAllActionsFromTarget(element.target, true);
this._putElement(element);
}
this._arrayTargets.length = 0;
this._hashTargets = js.createMap(true);
},
/**
* !#en
+9 -5
View File
@@ -77,7 +77,11 @@ Audio.State = {
/**
* @property {Number} PAUSED
*/
PAUSED: 2
PAUSED: 2,
/**
* @property {Number} STOPPED
*/
STOPPED: 3,
};
(function (proto) {
@@ -171,14 +175,14 @@ Audio.State = {
};
proto.pause = function () {
if (!this._element) return;
if (!this._element || this._state !== Audio.State.PLAYING) return;
this._unbindEnded();
this._element.pause();
this._state = Audio.State.PAUSED;
};
proto.resume = function () {
if (!this._element || this._state === Audio.State.PLAYING) return;
if (!this._element || this._state !== Audio.State.PAUSED) return;
this._bindEnded();
this._element.play();
this._state = Audio.State.PLAYING;
@@ -186,10 +190,10 @@ Audio.State = {
proto.stop = function () {
if (!this._element) return;
this._element.pause();
try {
this._element.currentTime = 0;
} catch (error) {}
this._element.pause();
// remove touchPlayList
for (let i = 0; i < touchPlayList.length; i++) {
if (touchPlayList[i].instance === this) {
@@ -199,7 +203,7 @@ Audio.State = {
}
this._unbindEnded();
this.emit('stop');
this._state = Audio.State.PAUSED;
this._state = Audio.State.STOPPED;
};
proto.setLoop = function (loop) {
+6 -4
View File
@@ -35,6 +35,7 @@ let _url2id = {};
let _audioPool = [];
let recycleAudio = function (audio) {
audio._finishCallback = null;
if (_audioPool.length < 32) {
audio.off('ended');
audio.off('stop');
@@ -44,7 +45,7 @@ let recycleAudio = function (audio) {
else {
audio.destroy();
}
}
};
let getAudioFromPath = function (path) {
var id = _instanceId++;
@@ -61,6 +62,10 @@ let getAudioFromPath = function (path) {
var audio = _audioPool.pop() || new Audio();
var callback = function () {
if (audio._finishCallback) {
audio._finishCallback();
}
var audioInList = getAudioFromId(this.id);
if (audioInList) {
delete _id2audio[this.id];
@@ -289,10 +294,7 @@ var audioEngine = {
var audio = getAudioFromId(audioID);
if (!audio)
return;
audio.off('ended', audio._finishCallback);
audio._finishCallback = callback;
audio.on('ended', audio._finishCallback);
},
/**
+2 -26
View File
@@ -93,7 +93,7 @@ let resetDebugSetting = function (mode) {
};
}
if (mode === DebugMode.INFO_FOR_WEB_PAGE) {
cc.log = cc.info = function () {
cc.log = function () {
logToWebPage(cc.js.formatStr.apply(null, arguments));
};
}
@@ -177,7 +177,6 @@ let resetDebugSetting = function (mode) {
}
if (CC_EDITOR) {
cc.log = Editor.log;
cc.info = Editor.info;
}
else if (mode === DebugMode.INFO) {
/**
@@ -206,29 +205,6 @@ let resetDebugSetting = function (mode) {
return console.log.apply(console, arguments);
};
}
/**
* !#en
* Outputs an informational message to the Cocos Creator Console (editor) or Web Console (runtime).
* - In Cocos Creator, info is blue.
* - In Firefox and Chrome, a small "i" icon is displayed next to these items in the Web Console's log.
* !#zh
* 输出一条信息消息到 Cocos Creator 编辑器的 Console 或运行时 Web 端的 Console 中。
* - 在 Cocos Creator 中,Info 信息显示是蓝色的。<br/>
* - 在 Firefox 和 Chrome 中,Info 信息有着小 “i” 图标。
* @method info
* @param {any} msg - A JavaScript string containing zero or more substitution strings.
* @param {any} ...subst - JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
*/
if (CC_JSB) {
cc.info = (scriptEngineType === "JavaScriptCore") ? function () {
(console.info || console.log).apply(console, arguments);
} : (console.info || console.log);
}
else {
cc.info = function () {
(console.info || console.log).apply(console, arguments);
};
}
}
};
@@ -290,7 +266,7 @@ cc.assertID = function (cond) {
* !#zh 调试模式
* @enum debug.DebugMode
* @memberof cc
*/
*/
var DebugMode = cc.Enum({
/**
* !#en The debug mode none.
+1 -1
View File
@@ -666,7 +666,7 @@ var game = {
localCanvas = window.sharedCanvas || wx.getSharedCanvas();
}
else if (CC_JSB) {
localCanvas = window.__cccanvas;
localCanvas = window.__canvas;
}
else {
localCanvas = canvas;
-1
View File
@@ -25,7 +25,6 @@
****************************************************************************/
var RawAsset = require('./CCRawAsset');
var js = cc.js;
/**
* !#en
+15 -2
View File
@@ -1,5 +1,6 @@
const renderer = require('../renderer');
const renderEngine = require('../renderer/render-engine');
const gfx = renderEngine.gfx;
const Texture2D = require('./CCTexture2D');
/**
@@ -24,7 +25,7 @@ let RenderTexture = cc.Class({
* @param {Number} [height]
* @method initWithSize
*/
initWithSize (width, height) {
initWithSize (width, height, depthStencilFormat) {
this.width = Math.floor(width || cc.visibleRect.width);
this.height = Math.floor(height || cc.visibleRect.height);
@@ -44,8 +45,20 @@ let RenderTexture = cc.Class({
}
opts = {
colors: [ this._texture ]
colors: [ this._texture ],
};
if (depthStencilFormat) {
let depthStencilBuffer = new gfx.RenderBuffer(renderer.device, depthStencilFormat, width, height);
if (depthStencilFormat === gfx.RB_FMT_D24S8) {
opts.depth = opts.stencil = depthStencilBuffer;
}
else if (depthStencilFormat === gfx.RB_FMT_S8) {
opts.stencil = depthStencilBuffer;
}
else if (depthStencilFormat === gl.RB_FMT_D16) {
opts.depth = depthStencilBuffer;
}
}
if (this._framebuffer) {
this._framebuffer.destroy();
+3 -2
View File
@@ -267,8 +267,9 @@ function refreshScene () {
// check animation editor
if (CC_EDITOR && !Editor.isBuilder) {
var AnimUtils = Editor.require('scene://utils/animation');
if (AnimUtils) {
var nowPreviewing = !!AnimUtils.Cache.animation;
var EditMode = Editor.require('scene://edit-mode');
if (AnimUtils && EditMode) {
var nowPreviewing = (EditMode.curMode().name === 'animation' && !!AnimUtils.Cache.animation);
if (nowPreviewing !== animationState.previewing) {
animationState.previewing = nowPreviewing;
if (nowPreviewing) {
+1 -1
View File
@@ -401,7 +401,7 @@ let Button = cc.Class({
// // Restore button status
let target = this.target;
let transition = this.transition;
if (transition === Transition.COLOR) {
if (transition === Transition.COLOR && this.interactable) {
target.color = this.normalColor;
} else if (transition === Transition.SCALE) {
target.scale = this._originalScale;
+28 -14
View File
@@ -217,8 +217,10 @@ var Component = cc.Class({
// We provide Pre methods, which are called right before something happens, and Post methods which are called right after something happens.
/**
* !#en Update is called every frame, if the Component is enabled.
* !#zh 如果该组件启用,则每帧调用 update。
* !#en Update is called every frame, if the Component is enabled.<br/>
* This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.
* !#zh 如果该组件启用,则每帧调用 update。<br/>
* 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
* @method update
* @param {Number} dt - the delta time in seconds it took to complete the last frame
* @protected
@@ -226,8 +228,10 @@ var Component = cc.Class({
update: null,
/**
* !#en LateUpdate is called every frame, if the Component is enabled.
* !#zh 如果该组件启用,则每帧调用 LateUpdate。
* !#en LateUpdate is called every frame, if the Component is enabled.<br/>
* This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.
* !#zh 如果该组件启用,则每帧调用 LateUpdate。<br/>
* 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
* @method lateUpdate
* @protected
*/
@@ -247,9 +251,11 @@ var Component = cc.Class({
/**
* !#en
* When attaching to an active node or its node first activated.
* onLoad is always called before any start functions, this allows you to order initialization of scripts.
* onLoad is always called before any start functions, this allows you to order initialization of scripts.<br/>
* This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.
* !#zh
* 当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行,这能用于安排脚本的初始化顺序。
* 当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行,这能用于安排脚本的初始化顺序。<br/>
* 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
* @method onLoad
* @protected
*/
@@ -258,33 +264,41 @@ var Component = cc.Class({
/**
* !#en
* Called before all scripts' update if the Component is enabled the first time.
* Usually used to initialize some logic which need to be called after all components' `onload` methods called.
* Usually used to initialize some logic which need to be called after all components' `onload` methods called.<br/>
* This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.
* !#zh
* 如果该组件第一次启用,则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。
* 如果该组件第一次启用,则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。<br/>
* 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
* @method start
* @protected
*/
start: null,
/**
* !#en Called when this component becomes enabled and its node is active.
* !#zh 当该组件被启用,并且它的节点也激活时。
* !#en Called when this component becomes enabled and its node is active.<br/>
* This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.
* !#zh 当该组件被启用,并且它的节点也激活时。<br/>
* 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
* @method onEnable
* @protected
*/
onEnable: null,
/**
* !#en Called when this component becomes disabled or its node becomes inactive.
* !#zh 当该组件被禁用或节点变为无效时调用。
* !#en Called when this component becomes disabled or its node becomes inactive.<br/>
* This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.
* !#zh 当该组件被禁用或节点变为无效时调用。<br/>
* 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
* @method onDisable
* @protected
*/
onDisable: null,
/**
* !#en Called when this component will be destroyed.
* !#zh 当该组件被销毁时调用
* !#en Called when this component will be destroyed.<br/>
* This is a lifecycle method. It may not be implemented in the super class. You can only call its super class method inside it. It should not be called manually elsewhere.
* !#zh 当该组件被销毁时调用<br/>
* 该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
* @method onDestroy
* @protected
*/
+10 -2
View File
@@ -464,6 +464,7 @@ let Label = cc.Class({
// Keep track of Node size
this.node.on(cc.Node.EventType.SIZE_CHANGED, this._updateRenderData, this);
this.node.on(cc.Node.EventType.ANCHOR_CHANGED, this._updateRenderData, this);
this._checkStringEmpty();
this._updateAssembler();
@@ -473,6 +474,7 @@ let Label = cc.Class({
onDisable () {
this._super();
this.node.off(cc.Node.EventType.SIZE_CHANGED, this._updateRenderData, this);
this.node.off(cc.Node.EventType.ANCHOR_CHANGED, this._updateRenderData, this);
},
onDestroy () {
@@ -541,7 +543,10 @@ let Label = cc.Class({
else {
if (!this._ttfTexture) {
this._ttfTexture = new cc.Texture2D();
this._ttfTexture.setPremultiplyAlpha(true);
// TTF texture in web will blend with canvas or body background color
if (!CC_JSB) {
this._ttfTexture.setPremultiplyAlpha(true);
}
this._assemblerData = this._assembler._getAssemblerData();
this._ttfTexture.initWithElement(this._assemblerData.canvas);
}
@@ -559,7 +564,10 @@ let Label = cc.Class({
}
// Setup blend function for premultiplied ttf label texture
if (this._texture === this._ttfTexture) {
this._srcBlendFactor = cc.macro.ONE;
this._srcBlendFactor = cc.macro.BlendFactor.ONE;
}
else {
this._srcBlendFactor = cc.macro.BlendFactor.SRC_ALPHA;
}
material.texture = this._texture;
this._updateMaterial(material);
+18 -14
View File
@@ -537,20 +537,22 @@ var Layout = cc.Class({
for (var i = 0; i < children.length; ++i) {
var child = children[i];
let childScaleX = Math.abs(child.scaleX);
let childScaleY = Math.abs(child.scaleY);
if (!child.activeInHierarchy) {
continue;
}
//for resizing children
if (this._resize === ResizeMode.CHILDREN) {
child.width = newChildWidth / child.scaleX;
child.width = newChildWidth / childScaleX;
if (this.type === Type.GRID) {
child.height = this.cellSize.height / child.scaleY;
child.height = this.cellSize.height / childScaleY;
}
}
var anchorX = child.anchorX;
var childBoundingBoxWidth = child.width * child.scaleX;
var childBoundingBoxHeight = child.height * child.scaleY;
var childBoundingBoxWidth = child.width * childScaleX;
var childBoundingBoxHeight = child.height * childScaleY;
if (secondMaxHeight > tempMaxHeight) {
tempMaxHeight = secondMaxHeight;
@@ -587,13 +589,13 @@ var Layout = cc.Class({
secondMaxHeight = childBoundingBoxHeight;
tempMaxHeight = 0;
}
nextX = leftBoundaryOfLayout + sign * (paddingX + anchorX * child.width);
nextX = leftBoundaryOfLayout + sign * (paddingX + anchorX * childBoundingBoxWidth);
row++;
}
}
var finalPositionY = fnPositionY(child, rowMaxHeight, row);
if (baseWidth >= (child.width + this.paddingLeft + this.paddingRight)) {
if (baseWidth >= (childBoundingBoxWidth + this.paddingLeft + this.paddingRight)) {
if (applyChildren) {
child.setPosition(cc.v2(nextX, finalPositionY));
}
@@ -633,7 +635,7 @@ var Layout = cc.Class({
var child = children[i];
if (child.activeInHierarchy) {
activeChildCount++;
newHeight += child.height * child.scaleY;
newHeight += child.height * Math.abs(child.scaleY);
}
}
@@ -681,21 +683,23 @@ var Layout = cc.Class({
for (var i = 0; i < children.length; ++i) {
var child = children[i];
let childScaleX = Math.abs(child.scaleX);
let childScaleY = Math.abs(child.scaleY);
if (!child.activeInHierarchy) {
continue;
}
//for resizing children
if (this.resizeMode === ResizeMode.CHILDREN) {
child.height = newChildHeight / child.scaleY;
child.height = newChildHeight / childScaleY;
if (this.type === Type.GRID) {
child.width = this.cellSize.width / child.scaleX;
child.width = this.cellSize.width / childScaleX;
}
}
var anchorY = child.anchorY;
var childBoundingBoxWidth = child.width * child.scaleX;
var childBoundingBoxHeight = child.height * child.scaleY;
var childBoundingBoxWidth = child.width * childScaleX;
var childBoundingBoxHeight = child.height * childScaleY;
if (secondMaxWidth > tempMaxWidth) {
tempMaxWidth = secondMaxWidth;
@@ -821,7 +825,7 @@ var Layout = cc.Class({
}
var fnPositionY = function (child, topOffset, row) {
return bottomBoundaryOfLayout + sign * (topOffset + child.anchorY * child.height * child.scaleY + paddingY + row * this.spacingY);
return bottomBoundaryOfLayout + sign * (topOffset + child.anchorY * child.height * Math.abs(child.scaleY) + paddingY + row * this.spacingY);
}.bind(this);
@@ -862,7 +866,7 @@ var Layout = cc.Class({
}
var fnPositionX = function (child, leftOffset, column) {
return leftBoundaryOfLayout + sign * (leftOffset + child.anchorX * child.width * child.scaleX + paddingX + column * this.spacingX);
return leftBoundaryOfLayout + sign * (leftOffset + child.anchorX * child.width * Math.abs(child.scaleX) + paddingX + column * this.spacingX);
}.bind(this);
var newWidth = 0;
@@ -910,7 +914,7 @@ var Layout = cc.Class({
var child = children[i];
if (child.activeInHierarchy) {
activeChildCount++;
newWidth += child.width * child.scaleX;
newWidth += child.width * Math.abs(child.scaleX);
}
}
newWidth += (activeChildCount - 1) * this.spacingX + this.paddingLeft + this.paddingRight;
+111 -55
View File
@@ -30,6 +30,7 @@ const math = renderEngine.math;
const StencilMaterial = renderEngine.StencilMaterial;
const RenderComponent = require('./CCRenderComponent');
const RenderFlow = require('../renderer/render-flow');
const Graphics = require('../graphics/graphics');
let _vec2_temp = cc.v2();
let _mat4_temp = math.mat4.create();
@@ -103,6 +104,7 @@ let Mask = cc.Class({
if (this._type !== MaskType.IMAGE_STENCIL) {
this.spriteFrame = null;
this.alphaThreshold = 0;
this._updateGraphics();
}
if (this._renderData) {
this.destroyRenderData(this._renderData);
@@ -174,11 +176,9 @@ let Mask = cc.Class({
cc.warnID(4201);
return;
}
if (this._frontMaterial) {
this._frontMaterial.alphaThreshold = this.alphaThreshold;
this._endMaterial.alphaThreshold = this.alphaThreshold;
this._frontMaterial.updateHash();
this._endMaterial._hash = -this._frontMaterial._hash;
if (this._material) {
this._material.alphaThreshold = this.alphaThreshold;
this._material.updateHash();
}
}
},
@@ -235,6 +235,67 @@ let Mask = cc.Class({
Type: MaskType,
},
onLoad () {
this._graphics = new Graphics();
this._graphics.node = this.node;
this._graphics.lineWidth = 0;
this._graphics.strokeColor = cc.color(0, 0, 0, 0);
},
onRestore () {
if (!this._graphics) {
this._graphics = new Graphics();
this._graphics.node = this.node;
this._graphics.lineWidth = 0;
}
if (this._type !== MaskType.IMAGE_STENCIL) {
this._updateGraphics();
}
},
onEnable () {
this._super();
if (this._type === MaskType.IMAGE_STENCIL) {
if (!this._spriteFrame || !this._spriteFrame.textureLoaded()) {
// Do not render when sprite frame is not ready
this.markForRender(false);
if (this._spriteFrame) {
this._spriteFrame.once('load', this._onTextureLoaded, this);
this._spriteFrame.ensureLoadTexture();
}
}
}
else {
this._updateGraphics();
}
this.node.on(cc.Node.EventType.POSITION_CHANGED, this._updateGraphics, this);
this.node.on(cc.Node.EventType.ROTATION_CHANGED, this._updateGraphics, this);
this.node.on(cc.Node.EventType.SCALE_CHANGED, this._updateGraphics, this);
this.node.on(cc.Node.EventType.SIZE_CHANGED, this._updateGraphics, this);
this.node.on(cc.Node.EventType.ANCHOR_CHANGED, this._updateGraphics, this);
this.node._renderFlag |= RenderFlow.FLAG_POST_RENDER;
this._activateMaterial();
},
onDisable () {
this._super();
this.node.off(cc.Node.EventType.POSITION_CHANGED, this._updateGraphics, this);
this.node.off(cc.Node.EventType.ROTATION_CHANGED, this._updateGraphics, this);
this.node.off(cc.Node.EventType.SCALE_CHANGED, this._updateGraphics, this);
this.node.off(cc.Node.EventType.SIZE_CHANGED, this._updateGraphics, this);
this.node.off(cc.Node.EventType.ANCHOR_CHANGED, this._updateGraphics, this);
this.node._renderFlag &= ~RenderFlow.FLAG_POST_RENDER;
},
onDestroy () {
this._super();
this._graphics.destroy();
},
_resizeNodeToTargetNode: CC_EDITOR && function () {
if(this.spriteFrame) {
let rect = this.spriteFrame.getRect();
@@ -242,7 +303,7 @@ let Mask = cc.Class({
}
},
_onTextureLoaded: function (event) {
_onTextureLoaded () {
// Mark render data dirty
if (this._renderData) {
this._renderData.uvDirty = true;
@@ -255,7 +316,7 @@ let Mask = cc.Class({
}
},
_applySpriteFrame: function (oldFrame) {
_applySpriteFrame (oldFrame) {
if (oldFrame && oldFrame.off) {
oldFrame.off('load', this._onTextureLoaded, this);
}
@@ -271,7 +332,7 @@ let Mask = cc.Class({
}
},
_activateMaterial: function () {
_activateMaterial () {
// cannot be activated if texture not loaded yet
if (this._type === MaskType.IMAGE_STENCIL && (!this.spriteFrame || !this.spriteFrame.textureLoaded())) {
this.markForRender(false);
@@ -281,42 +342,57 @@ let Mask = cc.Class({
// WebGL
if (cc.game.renderType !== cc.game.RENDER_TYPE_CANVAS) {
// Init material
if (!this._frontMaterial) {
this._frontMaterial = new StencilMaterial();
this._endMaterial = new StencilMaterial();
if (!this._material) {
this._material = new StencilMaterial();
}
// Reset material
if (this._type === MaskType.IMAGE_STENCIL) {
let texture = this.spriteFrame.getTexture();
this._frontMaterial.useTexture = true;
this._frontMaterial.useColor = true;
this._frontMaterial.texture = texture;
this._frontMaterial.alphaThreshold = this.alphaThreshold;
this._endMaterial.useTexture = true;
this._endMaterial.useColor = true;
this._endMaterial.texture = texture;
this._endMaterial.alphaThreshold = this.alphaThreshold;
this._material.useModel = false;
this._material.useTexture = true;
this._material.useColor = true;
this._material.texture = texture;
this._material.alphaThreshold = this.alphaThreshold;
}
else {
this._frontMaterial.useTexture = false;
this._frontMaterial.useColor = false;
this._endMaterial.useTexture = false;
this._endMaterial.useColor = false;
this._material.useModel = true;
this._material.useTexture = false;
this._material.useColor = false;
}
if (!this._material) {
this._updateMaterial(this._frontMaterial);
}
// Avoid next up mask material to be batch with the exit one
this._endMaterial._hash = -this._frontMaterial._hash;
}
this.markForRender(true);
},
_hitTest: function (cameraPt) {
_updateGraphics () {
let node = this.node;
let graphics = this._graphics;
// Share render data with graphics content
graphics.clear(false);
let width = node._contentSize.width;
let height = node._contentSize.height;
let x = -width * node._anchorPoint.x;
let y = -height * node._anchorPoint.y;
if (this._type === MaskType.RECT) {
graphics.rect(x, y, width, height);
}
else if (this._type === MaskType.ELLIPSE) {
let cx = x + width / 2,
cy = y + height / 2,
rx = width / 2,
ry = height / 2;
graphics.ellipse(cx, cy, rx, ry);
}
if (cc.game.renderType === cc.game.RENDER_TYPE_CANVAS) {
graphics.stroke();
}
else {
graphics.fill();
}
},
_hitTest (cameraPt) {
let node = this.node;
let size = node.getContentSize(),
w = size.width,
@@ -341,17 +417,17 @@ let Mask = cc.Class({
markForUpdateRenderData (enable) {
if (enable && this.enabledInHierarchy) {
this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA;
this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
}
else if (!enable) {
this.node._renderFlag &= ~(RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA);
this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
}
},
markForRender (enable) {
if (enable && this.enabledInHierarchy) {
this.node._renderFlag |= (RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA |
RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA);
RenderFlow.FLAG_POST_RENDER);
}
else if (!enable) {
this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_POST_RENDER);
@@ -360,27 +436,7 @@ let Mask = cc.Class({
disableRender () {
this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA |
RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA);
},
onEnable () {
this._super();
// for graphic stencil data
this._graphics = null;
this.node._renderFlag |= RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA;
this._activateMaterial();
},
onDisable () {
this._super();
this.node._renderFlag &= ~(RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA);
},
onDestroy () {
this._super();
this._frontMaterial = null;
this._endMaterial = null;
RenderFlow.FLAG_POST_RENDER);
},
});
+22 -10
View File
@@ -26,6 +26,7 @@
const RenderComponent = require('../components/CCRenderComponent');
const SpriteMaterial = require('../renderer/render-engine').SpriteMaterial;
const textureUtil = require('../utils/texture-util');
/**
* !#en
@@ -159,13 +160,12 @@ var MotionStreak = cc.Class({
this._texture = value;
if (!value) {
if (!value || !value.loaded) {
this.disableRender();
this._ensureLoadTexture();
}
else {
this.markForRender(true);
this.markForUpdateRenderData(true);
this._activateMaterial(true);
this._activateMaterial();
}
},
type: cc.Texture2D,
@@ -220,6 +220,7 @@ var MotionStreak = cc.Class({
if (!this._texture || !this._texture.loaded) {
this.disableRender();
this._ensureLoadTexture();
}
else {
this._activateMaterial();
@@ -227,18 +228,29 @@ var MotionStreak = cc.Class({
this.reset();
},
_activateMaterial (force) {
_ensureLoadTexture: function () {
if (this._texture && !this._texture.loaded) {
// load exists texture
let self = this;
textureUtil.postLoadTexture(this._texture, function () {
self._activateMaterial();
});
}
},
_activateMaterial () {
let material = this._material;
if (!material) {
material = this._material = new SpriteMaterial();
material.useColor = false;
}
else if (!force) {
return;
}
material.texture = this._texture;
this._updateMaterial(material);
if (this._texture && this._texture.loaded) {
material.texture = this._texture;
this._updateMaterial(material);
this.markForRender(true);
this.markForUpdateRenderData(true);
}
},
onFocusInEditor: CC_EDITOR && function () {
+15 -5
View File
@@ -887,26 +887,26 @@ let ScrollView = cc.Class({
if(layout && layout.enabledInHierarchy) {
layout.updateLayout();
}
let scrollViewSize = this.node.getContentSize();
let viewSize = this.content.parent.getContentSize();
let leftBottomPosition = this._convertToContentParentSpace(cc.v2(0, 0));
this._leftBoundary = leftBottomPosition.x;
this._bottomBoundary = leftBottomPosition.y;
let topRightPosition = this._convertToContentParentSpace(cc.v2(scrollViewSize.width, scrollViewSize.height));
let topRightPosition = this._convertToContentParentSpace(cc.v2(viewSize.width, viewSize.height));
this._rightBoundary = topRightPosition.x;
this._topBoundary = topRightPosition.y;
if (!CC_EDITOR) {
this._moveContentToTopLeft(scrollViewSize);
this._moveContentToTopLeft(viewSize);
}
}
},
_convertToContentParentSpace (position) {
let scrollViewPositionInWorldSpace = this.node.convertToWorldSpace(position);
let contentParent = this.content.parent;
return contentParent.convertToNodeSpaceAR(scrollViewPositionInWorldSpace);
let viewPositionInWorldSpace = contentParent.convertToWorldSpace(position);
return contentParent.convertToNodeSpaceAR(viewPositionInWorldSpace);
},
//this is for nested scrollview
@@ -1517,6 +1517,11 @@ let ScrollView = cc.Class({
if (this.content) {
this.content.off(NodeEvent.SIZE_CHANGED, this._calculateBoundary, this);
this.content.off(NodeEvent.SCALE_CHANGED, this._calculateBoundary, this);
if (this.content.parent) {
this.content.parent.off(NodeEvent.POSITION_CHANGED, this._calculateBoundary, this);
this.content.parent.off(NodeEvent.SCALE_CHANGED, this._calculateBoundary, this);
this.content.parent.off(NodeEvent.SIZE_CHANGED, this._calculateBoundary, this);
}
}
}
this._hideScrollbar();
@@ -1531,6 +1536,11 @@ let ScrollView = cc.Class({
if (this.content) {
this.content.on(NodeEvent.SIZE_CHANGED, this._calculateBoundary, this);
this.content.on(NodeEvent.SCALE_CHANGED, this._calculateBoundary, this);
if (this.content.parent) {
this.content.parent.on(NodeEvent.POSITION_CHANGED, this._calculateBoundary, this);
this.content.parent.on(NodeEvent.SCALE_CHANGED, this._calculateBoundary, this);
this.content.parent.on(NodeEvent.SIZE_CHANGED, this._calculateBoundary, this);
}
}
}
this._showScrollbar();
+1 -1
View File
@@ -582,7 +582,7 @@ var Sprite = cc.Class({
}
},
_onTextureLoaded: function (event) {
_onTextureLoaded: function () {
if (!this.isValid) {
return;
}
@@ -82,11 +82,13 @@ else {
sharedCanvas.width = this.node.width;
sharedCanvas.height = this.node.height;
}
this._tex.setPremultiplyAlpha(true);
this._tex.initWithElement(sharedCanvas);
this._sprite = this.node.getComponent(cc.Sprite);
if (!this._sprite) {
this._sprite = this.node.addComponent(cc.Sprite);
this._sprite.srcBlendFactor = cc.macro.BlendFactor.ONE;
}
this._sprite.spriteFrame = new cc.SpriteFrame(this._tex);
}
@@ -366,6 +366,7 @@ let EditBox = cc.Class({
_init () {
this._createBackgroundSprite();
this._createLabels();
this.node.on(cc.Node.EventType.SIZE_CHANGED, this._resizeChildNodes, this);
let impl = this._impl = new EditBoxImpl();
@@ -494,6 +495,25 @@ let EditBox = cc.Class({
}
},
_resizeChildNodes () {
let textLabelNode = this._textLabel.node,
placeholderLabelNode = this._placeholderLabel.node,
backgroundNode = this._background.node;
textLabelNode.x = -this.node.width/2;
textLabelNode.y = this.node.height/2;
textLabelNode.width = this.node.width;
textLabelNode.height = this.node.height;
placeholderLabelNode.x = -this.node.width/2;
placeholderLabelNode.y = this.node.height/2;
placeholderLabelNode.width = this.node.width;
placeholderLabelNode.height = this.node.height;
backgroundNode.width = this.node.width;
backgroundNode.height = this.node.height;
},
_showLabels () {
let displayText = this._textLabel.string;
this._textLabel.node.active = displayText !== '';
@@ -577,6 +597,14 @@ let EditBox = cc.Class({
this._impl.clear();
},
onEnable () {
this._impl && this._impl.onEnable();
},
onDisable () {
this._impl && this._impl.onDisable();
},
__preload () {
if (!CC_EDITOR) {
this._registerEvent();
@@ -42,6 +42,7 @@ let FOCUS_DELAY_FIREFOX = 0;
let math = cc.vmath;
let _matrix = math.mat4.create();
let _matrix_temp = math.mat4.create();
let _vec3 = cc.v3();
// polyfill
@@ -93,6 +94,25 @@ let EditBoxImpl = cc.Class({
this.__orientationChanged = null;
},
onEnable () {
if (!this._edTxt) {
return;
}
if (this._alwaysOnTop) {
this._edTxt.style.display = '';
}
else {
this._edTxt.style.display = 'none';
}
},
onDisable () {
if (!this._edTxt) {
return;
}
this._edTxt.style.display = 'none';
},
setTabIndex (index) {
if (this._edTxt) {
this._edTxt.tabIndex = index;
@@ -341,18 +361,30 @@ let EditBoxImpl = cc.Class({
_vec3.y = -node._anchorPoint.y * contentSize.height;
math.mat4.translate(_matrix, _matrix, _vec3);
let camera;
// can't find camera in editor
if (CC_EDITOR) {
camera = cc.Camera.main;
}
else {
camera = cc.Camera.findCamera(node);
}
camera.getWorldToCameraMatrix(_matrix_temp);
math.mat4.mul(_matrix_temp, _matrix_temp, _matrix);
scaleX /= dpr;
scaleY /= dpr;
let container = cc.game.container;
let a = _matrix.m00 * scaleX, b = _matrix.m01, c = _matrix.m04, d = _matrix.m05 * scaleY;
let a = _matrix_temp.m00 * scaleX, b = _matrix.m01, c = _matrix.m04, d = _matrix_temp.m05 * scaleY;
let offsetX = container && container.style.paddingLeft && parseInt(container.style.paddingLeft);
offsetX += viewport.x / dpr;
let offsetY = container && container.style.paddingBottom && parseInt(container.style.paddingBottom);
offsetY += viewport.y / dpr;
let tx = _matrix.m12 * scaleX + offsetX, ty = _matrix.m13 * scaleY + offsetY;
let tx = _matrix_temp.m12 * scaleX + offsetX, ty = _matrix_temp.m13 * scaleY + offsetY;
if (polyfill.zoomInvalid) {
this._updateSize(this._size.width * a, this._size.height * d);
+6 -2
View File
@@ -230,8 +230,12 @@ proto.load = function(resources, progressCallback, completeCallback) {
var singleRes = false;
var res;
if (!(resources instanceof Array)) {
singleRes = true;
resources = resources ? [resources] : [];
if (resources) {
singleRes = true;
resources = [resources];
} else {
resources = [];
}
}
_sharedResources.length = 0;
@@ -24,23 +24,8 @@
THE SOFTWARE.
****************************************************************************/
if (CC_JSB) {
module.exports = function (item, callback) {
var url = item.url;
var result = jsb.fileUtils.getDataFromFile(url);
if (result) {
return result;
}
else {
return new Error('Download binary file failed: ' + url);
}
};
}
else {
function downloadBinary (item, callback) {
var url = item.url;
var self = this;
var xhr = cc.loader.getXMLHttpRequest(),
errInfo = 'Load binary data failed: ' + url + '';
xhr.open('GET', url, true);
@@ -64,5 +49,4 @@ function downloadBinary (item, callback) {
xhr.send(null);
}
module.exports = downloadBinary;
}
module.exports = downloadBinary;
+25 -40
View File
@@ -23,49 +23,34 @@
THE SOFTWARE.
****************************************************************************/
if (CC_JSB) {
module.exports = function (item) {
var url = item.url;
var urlAppendTimestamp = require('./utils').urlAppendTimestamp;
var result = jsb.fileUtils.getStringFromFile(url);
if (typeof result === 'string' && result) {
return result;
}
else {
return new Error('Download text failed: ' + url);
}
};
}
else {
var urlAppendTimestamp = require('./utils').urlAppendTimestamp;
module.exports = function (item, callback) {
var url = item.url;
url = urlAppendTimestamp(url);
module.exports = function (item, callback) {
var url = item.url;
url = urlAppendTimestamp(url);
var xhr = cc.loader.getXMLHttpRequest(),
errInfo = 'Load text file failed: ' + url;
xhr.open('GET', url, true);
if (xhr.overrideMimeType) xhr.overrideMimeType('text\/plain; charset=utf-8');
xhr.onload = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
callback(null, xhr.responseText);
}
else {
callback({status:xhr.status, errorMessage:errInfo + '(wrong status)'});
}
var xhr = cc.loader.getXMLHttpRequest(),
errInfo = 'Load text file failed: ' + url;
xhr.open('GET', url, true);
if (xhr.overrideMimeType) xhr.overrideMimeType('text\/plain; charset=utf-8');
xhr.onload = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
callback(null, xhr.responseText);
}
else {
callback({status:xhr.status, errorMessage:errInfo + '(wrong readyState)'});
callback({status:xhr.status, errorMessage:errInfo + '(wrong status)'});
}
};
xhr.onerror = function(){
callback({status:xhr.status, errorMessage:errInfo + '(error)'});
};
xhr.ontimeout = function(){
callback({status:xhr.status, errorMessage:errInfo + '(time out)'});
};
xhr.send(null);
}
else {
callback({status:xhr.status, errorMessage:errInfo + '(wrong readyState)'});
}
};
}
xhr.onerror = function(){
callback({status:xhr.status, errorMessage:errInfo + '(error)'});
};
xhr.ontimeout = function(){
callback({status:xhr.status, errorMessage:errInfo + '(time out)'});
};
xhr.send(null);
};
+2 -2
View File
@@ -1130,7 +1130,7 @@ function initSys () {
sys.garbageCollect = function () {
// N/A in web
if (CC_JSB) {
__jsc__.garbageCollect();
jsb.garbageCollect();
}
};
@@ -1141,7 +1141,7 @@ function initSys () {
sys.dumpRoot = function () {
// N/A in web
if (CC_JSB) {
__jsc__.dumpRoot();
jsb.dumpRoot();
}
};
+2 -2
View File
@@ -274,8 +274,8 @@ cc.js.mixin(View.prototype, {
}
} else {
//disable
if (this.__resizeWithBrowserSize) {
this.__resizeWithBrowserSize = false;
if (this._resizeWithBrowserSize) {
this._resizeWithBrowserSize = false;
window.removeEventListener('resize', this._resizeEvent);
window.removeEventListener('orientationchange', this._orientationChange);
}
@@ -23,48 +23,11 @@
THE SOFTWARE.
****************************************************************************/
const Node = require('../../../CCNode');
const Mask = require('../../../components/CCMask');
const Graphics = require('../../../graphics/graphics');
const graphicsHandler = require('./graphics');
// for nested mask, we might need multiple graphics component to avoid data conflict
let _graphicsPool = [];
function getGraphics () {
let graphics = _graphicsPool.pop();
if (!graphics) {
let graphicsNode = new Node();
graphics = graphicsNode.addComponent(Graphics);
graphics.lineWidth = 0;
}
return graphics;
}
let beforeHandler = {
updateRenderData (comp) {},
updateGraphics (mask) {
let node = mask.node;
let graphics = mask._graphics;
// Share render data with graphics content
graphics.clear(false);
let width = node.width;
let height = node.height;
let x = -width * node.anchorX;
let y = -height * node.anchorY;
if (mask._type === Mask.Type.RECT) {
graphics.rect(x, y, width, height);
}
else if (mask._type === Mask.Type.ELLIPSE) {
let cx = x + width / 2,
cy = y + height / 2,
rx = width / 2,
ry = height / 2;
graphics.ellipse(cx, cy, rx, ry);
}
graphics.stroke();
},
draw (ctx, mask) {
let node = mask.node;
@@ -74,11 +37,8 @@ let beforeHandler = {
tx = matrix.m12, ty = matrix.m13;
ctx.save();
ctx.transform(a, b, c, d, tx, -ty);
// draw stencil
mask._graphics = getGraphics();
this.updateGraphics(mask);
graphicsHandler.draw(ctx, mask._graphics);
ctx.clip();
+6 -1
View File
@@ -9643,7 +9643,12 @@ Device.prototype._restoreIndexBuffer = function _restoreIndexBuffer () {
var gl = this._gl;
var ib = this._current.indexBuffer;
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ib ? ib._glID : null);
if (ib && ib._glID !== -1) {
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ib._glID);
}
else {
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
}
};
/**
+3 -3
View File
@@ -30,7 +30,7 @@
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
var gl = window.__ccgl;
var gl = window.__gl;
var _filterGL = [
[ gl.GL_NEAREST, gl.GL_NEAREST_MIPMAP_NEAREST, gl.GL_NEAREST_MIPMAP_LINEAR ],
@@ -369,11 +369,11 @@ VertexFormat.prototype.element = function element (attrName) {
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
var gl$1 = window.__ccgl;
var gl$1 = window.__gl;
var gfx$1 = window.gfx;
window.device = gfx$1.Device.getInstance();
window.device._gl = window.__ccgl;
window.device._gl = window.__gl;
//FIXME:
window.device._stats = { vb: 0 };
@@ -67,8 +67,6 @@ function Impl (graphics) {
this._renderDatas = [];
this._dataOffset = 0;
this.requestRenderData(graphics);
}
cc.js.mixin(Impl.prototype, {
@@ -217,7 +215,7 @@ cc.js.mixin(Impl.prototype, {
pathPoints.push(pt);
},
requestRenderData (graphics) {
requestRenderData () {
let renderData = new IARenderData();
let meshbuffer = new MeshBuffer(renderer._walker, vfmtPosColor);
renderData.meshbuffer = meshbuffer;
@@ -230,6 +228,14 @@ cc.js.mixin(Impl.prototype, {
renderData.ia = ia;
return renderData;
},
getRenderDatas () {
if (this._renderDatas.length === 0) {
this.requestRenderData();
}
return this._renderDatas;
}
});
@@ -69,7 +69,7 @@ let graphicsAssembler = {
},
updateRenderData (graphics) {
let datas = graphics._impl._renderDatas;
let datas = graphics._impl.getRenderDatas();
for (let i = 0, l = datas.length; i < l; i++) {
datas[i].material = graphics.getMaterial();
}
@@ -94,7 +94,7 @@ let graphicsAssembler = {
nodeA = nodeColor.a / 255;
let impl = graphics._impl;
let renderDatas = impl._renderDatas;
let renderDatas = impl.getRenderDatas();
for (let index = 0, length = renderDatas.length; index < length; index++) {
let renderData = renderDatas[index];
let meshbuffer = renderData.meshbuffer;
@@ -105,7 +105,7 @@ let graphicsAssembler = {
},
genRenderData (graphics, cverts) {
let renderDatas = _impl._renderDatas;
let renderDatas = _impl.getRenderDatas();
let renderData = renderDatas[_impl._dataOffset];
let meshbuffer = renderData.meshbuffer;
@@ -122,6 +122,9 @@ let graphicsAssembler = {
renderData = _impl.requestRenderData(graphics);
renderDatas[_impl._dataOffset] = renderData;
}
renderData.material = graphics.getMaterial();
meshbuffer = renderData.meshbuffer;
}
if (maxVertsCount > meshbuffer.vertexOffset) {
@@ -24,52 +24,34 @@
****************************************************************************/
const StencilManager = require('../stencil-manager');
const Node = require('../../../CCNode');
const Node = require('../../../CCNode');
const Mask = require('../../../components/CCMask');
const Graphics = require('../../../graphics/graphics');
const RenderFlow = require('../../render-flow');
const spriteAssembler = require('./sprite/simple');
const Graphics = require('../../../graphics/graphics');
const graphicsAssembler = require('./graphics');
let _stencilMgr = StencilManager.sharedManager;
// for nested mask, we might need multiple graphics component to avoid data conflict
// for nested mask, we might need multiple graphics component to avoid data conflict
let _graphicsPool = [];
function getGraphics () {
let graphics = _graphicsPool.pop();
let graphics = _graphicsPool.pop();
if (!graphics) {
let graphicsNode = new Node();
graphics = graphicsNode.addComponent(Graphics);
graphics._activateMaterial();
graphics.lineWidth = 0;
graphics.rect(0, 0, cc.visibleRect.width, cc.visibleRect.height);
graphics.fill();
graphicsAssembler.updateRenderData(graphics);
}
return graphics;
}
let maskFrontAssembler = {
updateGraphics (mask) {
let renderData = mask._renderData;
let graphics = mask._graphics;
// Share render data with graphics content
graphics.clear(false);
let width = renderData._width;
let height = renderData._height;
let x = -width * renderData._pivotX;
let y = -height * renderData._pivotY;
if (mask._type === Mask.Type.RECT) {
graphics.rect(x, y, width, height);
}
else if (mask._type === Mask.Type.ELLIPSE) {
let cx = x + width / 2,
cy = y + height / 2,
rx = width / 2,
ry = height / 2;
graphics.ellipse(cx, cy, rx, ry);
}
graphics.fill();
},
updateRenderData (mask) {
if (!mask._renderData) {
if (mask._type === Mask.Type.IMAGE_STENCIL) {
@@ -81,26 +63,21 @@ let maskFrontAssembler = {
}
}
let renderData = mask._renderData;
let size = mask.node._contentSize;
let anchor = mask.node._anchorPoint;
renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y);
mask._material = mask._frontMaterial;
if (mask._type === Mask.Type.IMAGE_STENCIL) {
mask._material.useModel = false;
if (mask.spriteFrame) {
let size = mask.node._contentSize;
let anchor = mask.node._anchorPoint;
renderData.updateSizeNPivot(size.width, size.height, anchor.x, anchor.y);
renderData.dataLength = 4;
spriteAssembler.updateRenderData(mask);
renderData.material = mask.getMaterial();
renderData.material = mask._material;
}
else {
mask._material = null;
}
}
else {
mask._material.useModel = true;
mask._graphics = getGraphics();
this.updateGraphics(mask);
mask._graphics._material = mask._material;
graphicsAssembler.updateRenderData(mask._graphics);
}
@@ -111,14 +88,21 @@ let maskFrontAssembler = {
if (mask._type !== Mask.Type.IMAGE_STENCIL || mask.spriteFrame) {
// HACK: Must push mask after batch, so we can only put this logic in fillVertexBuffer or fillIndexBuffer
_stencilMgr.pushMask(mask);
_stencilMgr.clear();
mask._clearGraphics = getGraphics();
graphicsAssembler.fillBuffers(mask._clearGraphics, renderer);
_stencilMgr.enterLevel();
// vertex buffer
renderer.node = mask.node;
renderer.material = mask._material;
if (mask._type === Mask.Type.IMAGE_STENCIL) {
spriteAssembler.fillBuffers(mask, renderer);
renderer._flush();
}
else {
// Share node for correct global matrix
mask._graphics.node = mask.node;
graphicsAssembler.fillBuffers(mask._graphics, renderer);
}
}
@@ -128,50 +112,17 @@ let maskFrontAssembler = {
};
let maskEndAssembler = {
updateRenderData (mask) {
if (mask._type === Mask.Type.IMAGE_STENCIL && !mask.spriteFrame) {
mask._material = null;
}
else {
mask._material = mask._endMaterial;
}
let material = mask._material;
if (mask._type === Mask.Type.IMAGE_STENCIL) {
material.useModel = false;
let data = mask._renderData;
data.material = material;
}
else {
material.useModel = true;
let datas = mask._graphics._impl._renderDatas;
for (let i = 0; i < datas.length; i++) {
datas[i].material = material;
}
}
},
fillBuffers (mask, renderer) {
// Invalid state
if (mask._type !== Mask.Type.IMAGE_STENCIL || mask.spriteFrame) {
// HACK: Must pop mask after batch, so we can only put this logic in fillBuffers
_stencilMgr.popMask();
_stencilMgr.exitMask();
// vertex buffer
if (mask._type === Mask.Type.IMAGE_STENCIL) {
spriteAssembler.fillBuffers(mask, renderer);
}
else {
// Share node for correct global matrix
mask._graphics.node = mask.node;
graphicsAssembler.fillBuffers(mask._graphics, renderer);
// put back graphics to pool
_graphicsPool.push(mask._graphics);
mask._graphics = null;
}
_graphicsPool.push(mask._clearGraphics);
mask._clearGraphics = null;
}
mask.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA;
mask.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
}
};
@@ -72,59 +72,9 @@ module.exports = {
let data = renderData._data;
renderData.dataLength = Math.max(8, row+1, col+1);
let l, b, r, t;
if (!frame._rotated) {
l = (rect.x) / texw;
r = (rect.x + rectWidth) / texw;
b = (rect.y + rectHeight) / texh;
t = (rect.y) / texh;
data[0].u = l;
data[0].v = b;
data[1].u = r;
data[1].v = b;
data[2].u = l;
data[2].v = t;
data[3].u = r;
data[3].v = t;
data[4].u = l;
data[4].v = b;
data[5].u = l + (r-l) * Math.min(1, hRepeat - col + 1);
data[5].v = b;
data[6].u = l;
data[6].v = b + (t-b) * Math.min(1, vRepeat - row + 1);
data[7].u = data[5].u;
data[7].v = data[6].v;
} else {
l = (rect.x) / texw;
r = (rect.x + rectHeight) / texw;
b = (rect.y + rectWidth) / texh;
t = (rect.y) / texh;
data[0].u = l;
data[0].v = t;
data[1].u = l;
data[1].v = b;
data[2].u = r;
data[2].v = t;
data[3].u = r;
data[3].v = b;
data[4].u = l;
data[4].v = t;
data[5].u = l;
data[5].v = t + (b - t) * Math.min(1, vRepeat - col + 1);
data[6].u = l + (r - l) * Math.min(1, hRepeat - row + 1);
data[6].v = t;
data[7].u = data[5].u;
data[7].v = data[6].v;
}
for (let i = 0; i <= col; ++i) {
data[i].x = Math.min(rectWidth * i, contentWidth) - appx;
}
for (let i = 0; i <= row; ++i) {
data[i].y = Math.min(rectHeight * i, contentHeight) - appy;
}
@@ -154,7 +104,8 @@ module.exports = {
let vbuf = buffer._vData,
ibuf = buffer._iData;
//
let rotated = sprite.spriteFrame._rotated;
let uv = sprite.spriteFrame.uv;
let rect = sprite.spriteFrame._rect;
let contentWidth = Math.abs(node.width);
let contentHeight = Math.abs(node.height);
@@ -167,39 +118,60 @@ module.exports = {
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
tx = matrix.m12, ty = matrix.m13;
let x, x1, y, y1, lastx, lasty;
let x, x1, y, y1, coefu, coefv;
for (let yindex = 0, ylength = row; yindex < ylength; ++yindex) {
y = data[yindex].y;
y1 = data[yindex+1].y;
coefv = Math.min(1, vRepeat - yindex);
for (let xindex = 0, xlength = col; xindex < xlength; ++xindex) {
lasty = yindex + 1 === ylength;
lastx = xindex + 1 === xlength;
coefu = Math.min(1, hRepeat - xindex);
x = data[xindex].x;
x1 = data[xindex+1].x;
// Vertex
// lb
vbuf[vertexOffset++] = x * a + y * c + tx;
vbuf[vertexOffset++] = x * b + y * d + ty;
vbuf[vertexOffset++] = lastx ? data[4].u : data[0].u;
vbuf[vertexOffset++] = lasty ? data[4].v : data[0].v;
vbuf[vertexOffset] = x * a + y * c + tx;
vbuf[vertexOffset+1] = x * b + y * d + ty;
// rb
vbuf[vertexOffset++] = x1 * a + y * c + tx;
vbuf[vertexOffset++] = x1 * b + y * d + ty;
vbuf[vertexOffset++] = lastx ? data[5].u : data[1].u;
vbuf[vertexOffset++] = lasty ? data[5].v : data[1].v;
vbuf[vertexOffset+4] = x1 * a + y * c + tx;
vbuf[vertexOffset+5] = x1 * b + y * d + ty;
// lt
vbuf[vertexOffset++] = x * a + y1 * c + tx;
vbuf[vertexOffset++] = x * b + y1 * d + ty;
vbuf[vertexOffset++] = lastx ? data[6].u : data[2].u;
vbuf[vertexOffset++] = lasty ? data[6].v : data[2].v;
vbuf[vertexOffset+8] = x * a + y1 * c + tx;
vbuf[vertexOffset+9] = x * b + y1 * d + ty;
// rt
vbuf[vertexOffset++] = x1 * a + y1 * c + tx;
vbuf[vertexOffset++] = x1 * b + y1 * d + ty;
vbuf[vertexOffset++] = lastx ? data[7].u : data[3].u;
vbuf[vertexOffset++] = lasty ? data[7].v : data[3].v;
vbuf[vertexOffset+12] = x1 * a + y1 * c + tx;
vbuf[vertexOffset+13] = x1 * b + y1 * d + ty;
// UV
if (rotated) {
// lb
vbuf[vertexOffset+2] = uv[0];
vbuf[vertexOffset+3] = uv[1];
// rb
vbuf[vertexOffset+6] = uv[0];
vbuf[vertexOffset+7] = uv[1] + (uv[7] - uv[1]) * coefu;
// lt
vbuf[vertexOffset+10] = uv[0] + (uv[6] - uv[0]) * coefv;
vbuf[vertexOffset+11] = uv[1];
// rt
vbuf[vertexOffset+14] = vbuf[vertexOffset+10];
vbuf[vertexOffset+15] = vbuf[vertexOffset+7];
}
else {
// lb
vbuf[vertexOffset+2] = uv[0];
vbuf[vertexOffset+3] = uv[1];
// rb
vbuf[vertexOffset+6] = uv[0] + (uv[6] - uv[0]) * coefu;
vbuf[vertexOffset+7] = uv[1];
// lt
vbuf[vertexOffset+10] = uv[0];
vbuf[vertexOffset+11] = uv[1] + (uv[7] - uv[1]) * coefv;
// rt
vbuf[vertexOffset+14] = vbuf[vertexOffset+6];
vbuf[vertexOffset+15] = vbuf[vertexOffset+11];
}
vertexOffset += 16;
}
}
+35 -16
View File
@@ -30,12 +30,14 @@ const gfx = renderEngine.gfx;
var Stage = cc.Enum({
// Stencil disabled
DISABLED: 0,
// Clear stencil buffer
CLEAR: 1,
// Entering a new level, should handle new stencil
ENTER_LEVEL: 1,
// In stencil
ENABLED: 2,
ENTER_LEVEL: 2,
// In content
ENABLED: 3,
// Exiting a level, should restore old stencil or disable
EXIT_LEVEL: 3,
EXIT_LEVEL: 4,
});
function StencilManager () {
@@ -86,18 +88,26 @@ StencilManager.prototype = {
stencilMask = ref;
}
failOp = gfx.STENCIL_OP_KEEP;
writeMask = 0;
writeMask = this.getWriteMask();
}
else {
func = gfx.DS_FUNC_NEVER;
failOp = gfx.STENCIL_OP_REPLACE;
if (this.stage === Stage.ENTER_LEVEL) {
if (this.stage === Stage.CLEAR) {
mask = this._maskStack[this._maskStack.length - 1];
func = gfx.DS_FUNC_NEVER;
ref = this.getWriteMask();
stencilMask = ref;
writeMask = ref;
failOp = mask.inverted ? gfx.STENCIL_OP_REPLACE : gfx.STENCIL_OP_ZERO;
}
else if (this.stage === Stage.ENTER_LEVEL) {
mask = this._maskStack[this._maskStack.length - 1];
this.stage = Stage.ENABLED;
// Fill stencil mask
ref = this.getStencilRef();
stencilMask = this.getWriteMask();
writeMask = stencilMask;
func = gfx.DS_FUNC_NEVER;
ref = this.getWriteMask();
stencilMask = ref;
writeMask = ref;
failOp = mask.inverted ? gfx.STENCIL_OP_ZERO : gfx.STENCIL_OP_REPLACE;
}
else if (this.stage === Stage.EXIT_LEVEL) {
// Pop mask after getting the correct stencil mask
@@ -108,9 +118,11 @@ StencilManager.prototype = {
this.stage = Stage.ENABLED;
}
// Clear stencil mask
ref = 0;
stencilMask = this.getExitWriteMask();
writeMask = stencilMask;
func = gfx.DS_FUNC_EQUAL;
ref = this.getExitWriteMask();
stencilMask = ref;
writeMask = ref;
failOp = gfx.STENCIL_OP_KEEP;
}
}
@@ -127,10 +139,17 @@ StencilManager.prototype = {
cc.errorID(9000, this._maxLevel);
}
this._maskStack.push(mask);
},
clear () {
this.stage = Stage.CLEAR;
},
enterLevel () {
this.stage = Stage.ENTER_LEVEL;
},
popMask () {
exitMask () {
if (this._maskStack.length === 0) {
cc.errorID(9001);
}
+2 -2
View File
@@ -95,8 +95,8 @@ cc.path = /** @lends cc.path# */{
basename: function (pathStr, extname) {
var index = pathStr.indexOf("?");
if (index > 0) pathStr = pathStr.substring(0, index);
var reg = /(\/|\\\\)([^(\/|\\\\)]+)$/g;
var result = reg.exec(pathStr.replace(/(\/|\\\\)$/, ""));
var reg = /(\/|\\)([^\/\\]+)$/g;
var result = reg.exec(pathStr.replace(/(\/|\\)$/, ""));
if (!result) return null;
var baseName = result[2];
if (extname && pathStr.substring(pathStr.length - extname.length).toLowerCase() === extname.toLowerCase())
-1
View File
@@ -25,7 +25,6 @@
****************************************************************************/
var js = require('../platform/js');
var sys = require('../platform/CCSys');
/**
* misc utilities
+1 -1
View File
@@ -57,7 +57,7 @@ let textureUtil = {
return cb && cb.call(target, err || new Error('Unknown error'));
}
texture.handleLoadedTexture();
cb && cb.call(target, texture);
cb && cb.call(target, null, texture);
});
return tex;
}
+8 -4
View File
@@ -263,7 +263,8 @@ var Color = (function () {
* color.setR(255); // Color {r: 255, g: 0, b: 0, a: 255}
*/
proto.setR = function (red) {
this._val = ((this._val & 0xffffff00) | ~~red) >>> 0;
red = ~~cc.misc.clampf(red, 0, 255);
this._val = ((this._val & 0xffffff00) | red) >>> 0;
return this;
};
/**
@@ -286,7 +287,8 @@ var Color = (function () {
* color.setG(255); // Color {r: 0, g: 255, b: 0, a: 255}
*/
proto.setG = function (green) {
this._val = ((this._val & 0xffff00ff) | (~~green << 8)) >>> 0;
green = ~~cc.misc.clampf(green, 0, 255);
this._val = ((this._val & 0xffff00ff) | (green << 8)) >>> 0;
return this;
};
/**
@@ -309,7 +311,8 @@ var Color = (function () {
* color.setB(255); // Color {r: 0, g: 0, b: 255, a: 255}
*/
proto.setB = function (blue) {
this._val = ((this._val & 0xff00ffff) | (~~blue << 16)) >>> 0;
blue = ~~cc.misc.clampf(blue, 0, 255);
this._val = ((this._val & 0xff00ffff) | (blue << 16)) >>> 0;
return this;
};
/**
@@ -332,7 +335,8 @@ var Color = (function () {
* color.setA(0); // Color {r: 0, g: 0, b: 0, a: 0}
*/
proto.setA = function (alpha) {
this._val = ((this._val & 0x00ffffff) | ((~~alpha << 24) >>> 0)) >>> 0;
alpha = ~~cc.misc.clampf(alpha, 0, 255);
this._val = ((this._val & 0x00ffffff) | ((alpha << 24) >>> 0)) >>> 0;
return this;
};
+3 -3
View File
@@ -171,7 +171,7 @@ proto.set = function (source) {
* !#zh 当前矩形与指定矩形是否相交。
* @method intersects
* @param {Rect} rect
* @type {Boolean}
* @return {Boolean}
* @example
* var a = new cc.Rect(0, 0, 10, 10);
* var b = new cc.Rect(0, 0, 20, 20);
@@ -214,7 +214,7 @@ proto.intersection = function (out, rectB) {
* Returns true if the point inside this rectangle.
* @method contains
* @param {Vec2} point
* @type {Boolean}
* @return {Boolean}
* @example
* var a = new cc.Rect(0, 0, 10, 10);
* var b = new cc.Vec2(0, 5);
@@ -232,7 +232,7 @@ proto.contains = function (point) {
* !#zh 当前矩形是否包含指定矩形。
* @method containsRect
* @param {Rect} rect
* @type {Boolean}
* @return {Boolean}
* @example
* var a = new cc.Rect(0, 0, 20, 20);
* var b = new cc.Rect(0, 0, 10, 10);
+9 -5
View File
@@ -26,7 +26,7 @@
var js = cc.js;
if (CC_DEV) {
if (CC_DEBUG) {
function deprecateEnum (obj, oldPath, newPath, hasTypePrefixBefore) {
if (!CC_SUPPORT_JIT) {
@@ -138,12 +138,16 @@ if (CC_DEV) {
cc.warn('Sorry, %s.%s is deprecated. Please use %s instead', ownerName, propName, obj[propName]);
return originFunc.apply(this, arguments);
}
ownerCtor[propName] = warn;
})();
}
}
// remove cc.info
js.get(cc, 'info', function () {
cc.warnID(1400, 'cc.info', 'cc.log');
return cc.log;
});
// cc.spriteFrameCache
js.get(cc, "spriteFrameCache", function () {
cc.errorID(1404);
@@ -434,7 +438,7 @@ if (CC_DEV) {
// Vec2
pointEqualToPoint: 'cc.Vec2 equals',
// Size
sizeEqualToSize: 'cc.Size equals',
@@ -576,7 +580,7 @@ if (CC_DEV) {
cc.errorID(1407);
return js.Pool;
});
// cc.isChildClassOf
js.get(cc, 'isChildClassOf', function () {
cc.errorID(1400, 'cc.isChildClassOf', 'cc.js.isChildClassOf');
+49 -27
View File
@@ -363,11 +363,12 @@ var properties = {
/**
* !#en Start color of each particle.
* !#zh 粒子初始颜色。
* @property {Object} startColor
* @property {cc.Color} startColor
* @default {r: 255, g: 255, b: 255, a: 255}
*/
_startColor: null,
startColor: {
type: cc.Color,
get () {
return this._startColor;
},
@@ -381,11 +382,12 @@ var properties = {
/**
* !#en Variation of the start color.
* !#zh 粒子初始颜色变化范围。
* @property {Object} startColorVar
* @property {cc.Color} startColorVar
* @default {r: 0, g: 0, b: 0, a: 0}
*/
_startColorVar: null,
startColorVar: {
type: cc.Color,
get () {
return this._startColorVar;
},
@@ -399,11 +401,12 @@ var properties = {
/**
* !#en Ending color of each particle.
* !#zh 粒子结束颜色。
* @property {Object} endColor
* @property {cc.Color} endColor
* @default {r: 255, g: 255, b: 255, a: 0}
*/
_endColor: null,
endColor: {
type: cc.Color,
get () {
return this._endColor;
},
@@ -417,11 +420,12 @@ var properties = {
/**
* !#en Variation of the end color.
* !#zh 粒子结束颜色变化范围。
* @property {Object} endColorVar
* @property {cc.Color} endColorVar
* @default {r: 0, g: 0, b: 0, a: 0}
*/
_endColorVar: null,
endColorVar: {
type: cc.Color,
get () {
return this._endColorVar;
},
@@ -752,6 +756,10 @@ var ParticleSystem = cc.Class({
EmitterMode: EmitterMode,
PositionType: PositionType,
_PNGReader: PNGReader,
_TIFFReader: tiffReader,
},
// EDITOR RELATED METHODS
@@ -810,6 +818,13 @@ var ParticleSystem = cc.Class({
this.resetSystem();
}
}
// Upgrade color type from v2.0.0
if (CC_EDITOR && !(this._startColor instanceof cc.Color)) {
this._startColor = cc.color(this._startColor);
this._startColorVar = cc.color(this._startColorVar);
this._endColor = cc.color(this._endColor);
this._endColorVar = cc.color(this._endColorVar);
}
},
onLoad () {
@@ -943,9 +958,15 @@ var ParticleSystem = cc.Class({
// texture
if (dict["textureFileName"]) {
// Try to get the texture from the cache
var tex = textureUtil.loadImage(imgPath);
// TODO: Use cc.loader to load asynchronously the SpriteFrame object, avoid using textureUtil
this.spriteFrame = new cc.SpriteFrame(tex);
textureUtil.loadImage(imgPath, function (error, texture) {
if (error) {
dict["textureFileName"] = undefined;
this._initTextureWithDictionary(dict);
}
else {
this.spriteFrame = new cc.SpriteFrame(texture);
}
}, this);
} else if (dict["textureImageData"]) {
var textureData = dict["textureImageData"];
@@ -1002,29 +1023,29 @@ var ParticleSystem = cc.Class({
this.dstBlendFactor = parseInt(dict["blendFuncDestination"] || macro.ONE_MINUS_SRC_ALPHA);
// color
var locStartColor = this.startColor;
locStartColor.r = parseFloat(dict["startColorRed"] || 1) * 255;
locStartColor.g = parseFloat(dict["startColorGreen"] || 1) * 255;
locStartColor.b = parseFloat(dict["startColorBlue"] || 1) * 255;
locStartColor.a = parseFloat(dict["startColorAlpha"] || 1) * 255;
var locStartColor = this._startColor;
locStartColor.r = parseFloat(dict["startColorRed"] || 0) * 255;
locStartColor.g = parseFloat(dict["startColorGreen"] || 0) * 255;
locStartColor.b = parseFloat(dict["startColorBlue"] || 0) * 255;
locStartColor.a = parseFloat(dict["startColorAlpha"] || 0) * 255;
var locStartColorVar = this.startColorVar;
locStartColorVar.r = parseFloat(dict["startColorVarianceRed"] || 1) * 255;
locStartColorVar.g = parseFloat(dict["startColorVarianceGreen"] || 1) * 255;
locStartColorVar.b = parseFloat(dict["startColorVarianceBlue"] || 1) * 255;
locStartColorVar.a = parseFloat(dict["startColorVarianceAlpha"] || 1) * 255;
var locStartColorVar = this._startColorVar;
locStartColorVar.r = parseFloat(dict["startColorVarianceRed"] || 0) * 255;
locStartColorVar.g = parseFloat(dict["startColorVarianceGreen"] || 0) * 255;
locStartColorVar.b = parseFloat(dict["startColorVarianceBlue"] || 0) * 255;
locStartColorVar.a = parseFloat(dict["startColorVarianceAlpha"] || 0) * 255;
var locEndColor = this.endColor;
locEndColor.r = parseFloat(dict["finishColorRed"] || 1) * 255;
locEndColor.g = parseFloat(dict["finishColorGreen"] || 1) * 255;
locEndColor.b = parseFloat(dict["finishColorBlue"] || 1) * 255;
locEndColor.a = parseFloat(dict["finishColorAlpha"] || 1) * 255;
var locEndColor = this._endColor;
locEndColor.r = parseFloat(dict["finishColorRed"] || 0) * 255;
locEndColor.g = parseFloat(dict["finishColorGreen"] || 0) * 255;
locEndColor.b = parseFloat(dict["finishColorBlue"] || 0) * 255;
locEndColor.a = parseFloat(dict["finishColorAlpha"] || 0) * 255;
var locEndColorVar = this.endColorVar;
locEndColorVar.r = parseFloat(dict["finishColorVarianceRed"] || 1) * 255;
locEndColorVar.g = parseFloat(dict["finishColorVarianceGreen"] || 1) * 255;
locEndColorVar.b = parseFloat(dict["finishColorVarianceBlue"] || 1) * 255;
locEndColorVar.a = parseFloat(dict["finishColorVarianceAlpha"] || 1) * 255;
var locEndColorVar = this._endColorVar;
locEndColorVar.r = parseFloat(dict["finishColorVarianceRed"] || 0) * 255;
locEndColorVar.g = parseFloat(dict["finishColorVarianceGreen"] || 0) * 255;
locEndColorVar.b = parseFloat(dict["finishColorVarianceBlue"] || 0) * 255;
locEndColorVar.a = parseFloat(dict["finishColorVarianceAlpha"] || 0) * 255;
// particle size
this.startSize = parseFloat(dict["startParticleSize"] || 0);
@@ -1154,3 +1175,4 @@ var ParticleSystem = cc.Class({
});
cc.ParticleSystem = module.exports = ParticleSystem;
+9 -8
View File
@@ -293,8 +293,9 @@ Simulator.prototype.step = function (dt) {
}
this.elapsed += dt;
if (psys.duration !== -1 && psys.duration < this.elapsed)
if (psys.duration !== -1 && psys.duration < this.elapsed) {
psys.stopSystem();
}
}
// Request buffer for particles
@@ -315,10 +316,11 @@ Simulator.prototype.step = function (dt) {
_tpa.x = _tpa.y = _tpb.x = _tpb.y = _tpc.x = _tpc.y = 0;
let particle = particles[particleIdx];
// life
particle.timeToLive -= dt;
if (particle.timeToLive > 0) {
// life
particle.timeToLive -= dt;
// Mode A: gravity, direction, tangential accel & radial accel
if (psys.emitterMode === cc.ParticleSystem.EmitterMode.GRAVITY) {
let tmp = _tpc, radial = _tpa, tangential = _tpb;
@@ -401,11 +403,6 @@ Simulator.prototype.step = function (dt) {
}
pool.put(deadParticle);
particles.length--;
if (particles.length === 0) {
this.finished = true;
psys._finishedSimulation();
}
}
}
@@ -413,6 +410,10 @@ Simulator.prototype.step = function (dt) {
buffer.uploadData();
psys._ia._count = particles.length * 6;
}
else if (!this.active) {
this.finished = true;
psys._finishedSimulation();
}
}
module.exports = Simulator;
+40 -35
View File
@@ -25,6 +25,8 @@
THE SOFTWARE.
****************************************************************************/
'use strict';
const codec = require('../compression/ZipUtils');
const zlib = require('../compression/zlib.min');
const js = require('../core/platform/js');
@@ -189,7 +191,7 @@ cc.TMXTilesetInfo.prototype = {
}
};
function getPropertyList (node) {
function getPropertyList (node, map) {
let res = [];
let properties = node.getElementsByTagName("properties");
for (let i = 0; i < properties.length; ++i) {
@@ -198,7 +200,36 @@ function getPropertyList (node) {
res.push(property[j]);
}
}
return res.length ? res : null;
map = map || {};
for (let i = 0; i < res.length; i++) {
let element = res[i];
let name = element.getAttribute('name');
let type = element.getAttribute('type') || 'string';
let value = element.getAttribute('value');
if (type === 'int') {
value = parseInt(value);
}
else if (type === 'float') {
value = parseFloat(value);
}
else if (type === 'bool') {
value = value === 'true';
}
else if (type === 'color') {
value = (value.indexOf('#') === 0) ? value.substring(1) : value;
let a = parseInt(value.substr(0, 2), 16) || 255;
let r = parseInt(value.substr(2, 2), 16) || 0;
let g = parseInt(value.substr(4, 2), 16) || 0;
let b = parseInt(value.substr(6, 2), 16) || 0;
value = cc.color(r, g, b, a);
}
map[name] = value;
}
return map;
}
/**
@@ -624,14 +655,7 @@ cc.TMXMapInfo.prototype = {
this.setTileSize(mapSize);
// The parent element is the map
let propertyArr = getPropertyList(map);
if (propertyArr) {
let aPropertyDict = {};
for (i = 0; i < propertyArr.length; i++) {
aPropertyDict[propertyArr[i].getAttribute('name')] = propertyArr[i].getAttribute('value');
}
this.properties = aPropertyDict;
}
this.properties = getPropertyList(map);
}
// PARSE <tileset>
@@ -692,15 +716,7 @@ cc.TMXMapInfo.prototype = {
for (let tIdx = 0; tIdx < tiles.length; tIdx++) {
let t = tiles[tIdx];
this.parentGID = parseInt(tileset.firstGid) + parseInt(t.getAttribute('id') || 0);
let tp = getPropertyList(t);
if (tp) {
let dict = {};
for (j = 0; j < tp.length; j++) {
let name = tp[j].getAttribute('name');
dict[name] = tp[j].getAttribute('value');
}
this._tileProperties[this.parentGID] = dict;
}
this._tileProperties[this.parentGID] = getPropertyList(t);
}
}
}
@@ -839,15 +855,8 @@ cc.TMXMapInfo.prototype = {
if (draworder)
objectGroup._draworder = draworder;
let groupProps = getPropertyList(selGroup);
if (groupProps) {
let parsedProps = {};
for (let j = 0; j < groupProps.length; j++) {
parsedProps[groupProps[j].getAttribute('name')] = groupProps[j].getAttribute('value');
}
// set the properties to the group
objectGroup.setProperties(parsedProps);
}
// set the properties to the group
objectGroup.setProperties(getPropertyList(selGroup));
let objects = selGroup.getElementsByTagName('object');
if (objects) {
@@ -867,16 +876,12 @@ cc.TMXMapInfo.prototype = {
objectProp["width"] = parseFloat(selObj.getAttribute('width')) || 0;
objectProp["height"] = parseFloat(selObj.getAttribute('height')) || 0;
objectProp["x"] = (selObj.getAttribute('x') || 0);
objectProp["y"] = (selObj.getAttribute('y') || 0);
objectProp["x"] = parseFloat(selObj.getAttribute('x')) || 0;
objectProp["y"] = parseFloat(selObj.getAttribute('y')) || 0;
objectProp["rotation"] = parseFloat(selObj.getAttribute('rotation')) || 0;
let docObjProps = getPropertyList(selObj);
if (docObjProps) {
for (let k = 0; k < docObjProps.length; k++)
objectProp[docObjProps[k].getAttribute('name')] = docObjProps[k].getAttribute('value');
}
getPropertyList(selObj, objectProp);
// visible
let visibleAttr = selObj.getAttribute('visible');
+18 -18
View File
@@ -154,36 +154,36 @@ let TiledLayer = cc.Class({
);
},
_positionForHexAt (x, y) {
let xy;
_positionForHexAt (row, col) {
let tileWidth = this._mapTileSize.width;
let tileHeight = this._mapTileSize.height;
let cols = this._layerSize.height;
let offset = this._tileset.tileOffset;
let centerWidth = this.node.width / 2;
let centerHeight = this.node.height / 2;
let odd_even = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? 1 : -1;
let x = 0, y = 0;
switch (this._staggerAxis) {
case cc.TiledMap.StaggerAxis.STAGGERAXIS_Y:
let diffX = 0;
if (y % 2 === 1)
{
diffX = this._mapTileSize.width/2 * odd_even;
let diffX1 = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? 0 : tileWidth / 2;
if (col % 2 === 1) {
diffX = tileWidth / 2 * odd_even;
}
xy = cc.v2(x * this._mapTileSize.width+diffX+offset.x,
(this._layerSize.height - y - 1) * (this._mapTileSize.height-(this._mapTileSize.height-this._hexSideLength)/2)-offset.y);
x = row * tileWidth + diffX + diffX1 + offset.x - centerWidth;
y = (cols - col - 1) * (tileHeight - (tileHeight - this._hexSideLength) / 2) - offset.y - centerHeight;
break;
case cc.TiledMap.StaggerAxis.STAGGERAXIS_X:
let diffY = 0;
if (x % 2 === 1)
{
diffY = this._mapTileSize.height/2 * -odd_even;
let diffY1 = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? tileHeight / 2 : 0;
if (row % 2 === 1) {
diffY = tileHeight / 2 * -odd_even;
}
xy = cc.v2(x * (this._mapTileSize.width-(this._mapTileSize.width-this._hexSideLength)/2)+offset.x,
(this._layerSize.height - y - 1) * this._mapTileSize.height + diffY-offset.y);
break;
default:
xy = cc.v2(0, 0);
x = row * (tileWidth - (tileWidth - this._hexSideLength) / 2) + offset.x - centerWidth;
y = (cols - col - 1) * tileHeight + diffY + diffY1 - offset.y - centerHeight;
break;
}
return xy;
return cc.v2(x, y);
},
/**
+23 -12
View File
@@ -423,12 +423,14 @@ let TiledMap = cc.Class({
return this._tileProperties[GID];
},
onEnable () {
__preload () {
if (this._tmxFile) {
// refresh layer entities
this._applyFile();
}
},
onEnable () {
this.node.on(cc.Node.EventType.ANCHOR_CHANGED, this._syncAnchorPoint, this);
},
@@ -462,6 +464,24 @@ let TiledMap = cc.Class({
this._buildWithMapInfo(mapInfo);
}
else {
this._relseasMapInfo()
}
},
_relseasMapInfo () {
// remove the layers & object groups added before
let layers = this._layers;
for (let i = 0, l = layers.length; i < l; i++) {
layers[i].node.removeFromParent();
}
layers.length = 0;
let groups = this._groups;
for (let i = 0, l = groups.length; i < l; i++) {
groups[i].node.removeFromParent();
}
groups.length = 0;
},
_syncAnchorPoint () {
@@ -478,19 +498,10 @@ let TiledMap = cc.Class({
this._properties = mapInfo.properties;
this._tileProperties = mapInfo.getTileProperties();
// remove the layers & object groups added before
this._relseasMapInfo();
let layers = this._layers;
for (let i = 0, l = layers.length; i < l; i++) {
layers[i].node.removeFromParent();
}
layers.length = 0;
let groups = this._groups;
for (let i = 0, l = groups.length; i < l; i++) {
groups[i].node.removeFromParent();
}
groups.length = 0;
let node = this.node;
let layerInfos = mapInfo.getAllChildren();
if (layerInfos && layerInfos.length > 0) {
+3 -4
View File
@@ -142,13 +142,12 @@ let TiledObjectGroup = cc.Class({
let objects = groupInfo._objects;
for (let i = 0, l = objects.length; i < l; i++) {
let object = objects[i];
object.offset = cc.v2(object.x, object.y);
if (cc.TiledMap.Orientation.ISO !== this._mapOrientation) {
object.y = height - object.y;
} else {
let mapSize = mapInfo.getMapSize();
let tileSize = mapInfo.getTileSize();
let posIdxX = (this._container.offset.x + offset.x) / tileSize.width * 2;
let posIdxY = (this._container.offset.y + offset.y) / tileSize.height;
let posIdxX = object.offset.x / tileSize.width * 2;
let posIdxY = object.offset.y / tileSize.height;
object.x = tileSize.width / 2 * (mapSize.width + posIdxX - posIdxY);
object.y = tileSize.height / 2 * (mapSize.height * 2 - posIdxX - posIdxY);
}
+16 -44
View File
@@ -42,12 +42,13 @@ let TiledTile = cc.Class({
menu: 'i18n:MAIN_MENU.component.renderers/TiledTile',
},
ctor () {
this._layer = null;
},
properties: {
_x: 0,
_y: 0,
_gid: 0,
_layer: null,
/**
* !#en Specify the TiledTile horizontal coordinate,use map tile as the unit.
@@ -103,52 +104,25 @@ let TiledTile = cc.Class({
*/
gid: {
get () {
return this._gid;
if (this._layer) {
return this._layer.getTileGIDAt(this._x, this._y);
}
return 0;
},
set (value) {
this._gid = value;
if (this._layer) {
this._layer.setTileGIDAt(value, this._x, this._y);
}
},
type: cc.Integer
},
/**
* !#en Specify which TiledLayer the TiledTile belong to.
* !#zh 指定 TiledTile 属于哪一个 TiledLayer
* @property {TiledLayer} layer
*/
layer: {
type: cc.TiledLayer,
get () {
return this._layer;
},
set (value) {
if (value === this._layer) return;
this._resetTile();
this._layer = value;
this._updateInfo();
}
}
},
onEnable () {
if (CC_EDITOR) {
let parent = this.node.parent;
if (!this._layer && !(parent instanceof cc.Scene)) {
this._layer = parent.getComponent(cc.TiledLayer);
this._updateInfo();
}
}
else if (this._layer) {
let tile = this._layer.getTiledTileAt(this._x, this._y);
if (tile) {
if (tile !== this) {
cc.warn('There is already a TiledTile at [%s, %s]', this._x, this._x);
}
}
else {
this._layer.setTiledTileAt(this._x, this._y, this);
}
}
let parent = this.node.parent;
this._layer = parent.getComponent(cc.TiledLayer);
this._resetTile();
this._updateInfo();
},
onDisable () {
@@ -163,15 +137,13 @@ let TiledTile = cc.Class({
_updateInfo () {
if (!this._layer) return;
let x = this._x, y = this._y;
if (this._layer.getTiledTileAt(x, y)) {
cc.warn('There is already a TiledTile at [%s, %s]', x, y);
return;
}
this.node.setPosition(this._layer.getPositionAt(x, y));
this._gid = this._layer.getTileGIDAt(x, y);
this._layer.setTiledTileAt(x, y, this);
},
});
+3 -1
View File
@@ -104,6 +104,7 @@ let tmxAssembler = {
let renderData = comp._renderData;
let data = renderData._data;
let color = node._color._val;
let opacity = node._color.a;
renderData.dataLength = renderData.vertexCount = renderData.indiceCount = 0;
@@ -254,7 +255,8 @@ let tmxAssembler = {
// color
color2 = color;
color = tiledNode.color._val;
let newOpacity = (tiledNode.opacity * opacity) / 255;
color = tiledNode.color.setA(newOpacity)._val;
// transform
a2 = a; b2 = b; c2 = c; d2 = d; tx2 = tx; ty2 = ty;
+16 -4
View File
@@ -347,10 +347,22 @@ let VideoPlayerImpl = cc.Class({
let video = this._video;
if (!video) return;
if (enable)
cc.screen.requestFullScreen(video);
else
cc.screen.exitFullScreen(video);
if (sys.os === sys.OS_IOS && sys.isBrowser) {
if (enable) {
video.webkitEnterFullscreen && video.webkitEnterFullscreen();
}
else {
video.webkitExitFullscreen && video.webkitExitFullscreen();
}
}
else {
if (enable) {
cc.screen.requestFullScreen(video);
}
else {
cc.screen.exitFullScreen(video);
}
}
},
+1 -1
View File
@@ -46,7 +46,7 @@ var dragonBones;
this._objects = [];
this._eventManager = null;
this._eventManager = eventManager;
console.info("DragonBones: " + DragonBones.VERSION + "\nWebsite: http://dragonbones.com/\nSource and Demos: https://github.com/DragonBones/");
console.log("DragonBones: " + DragonBones.VERSION + "\nWebsite: http://dragonbones.com/\nSource and Demos: https://github.com/DragonBones/");
}
DragonBones.prototype.advanceTime = function (passedTime) {
if (this._objects.length > 0) {
+2 -5
View File
@@ -28,7 +28,6 @@ const TrackEntryListeners = require('./track-entry-listeners');
const RenderComponent = require('../../cocos2d/core/components/CCRenderComponent');
const spine = require('./lib/spine');
const SpriteMaterial = require('../../cocos2d/core/renderer/render-engine').SpriteMaterial;
const Node = require('../../cocos2d/core/CCNode');
const Graphics = require('../../cocos2d/core/graphics/graphics');
/**
@@ -327,9 +326,7 @@ sp.Skeleton = cc.Class({
this._material = new SpriteMaterial();
this._renderDatas = [];
if (CC_DEBUG) {
this._debugRenderer = null;
}
this._debugRenderer = null;
},
/**
@@ -918,7 +915,7 @@ sp.Skeleton = cc.Class({
Editor.Utils.refreshSelectedInspector('node', this.node.uuid);
},
_initDebugDraw: CC_DEBUG && function () {
_initDebugDraw: function () {
if (this.debugBones || this.debugSlots) {
if (!this._debugRenderer) {
let debugDrawNode = new cc.PrivateNode();
+3 -3
View File
@@ -124,7 +124,7 @@ var spineAssembler = {
dataOffset++;
}
if (CC_DEBUG && comp.debugSlots && vertexCount === 4) {
if (comp.debugSlots && vertexCount === 4) {
let graphics = comp._debugRenderer;
// Debug Slot
@@ -147,7 +147,7 @@ var spineAssembler = {
let premultiAlpha = comp.premultipliedAlpha;
let graphics = comp._debugRenderer;
if (CC_DEBUG && comp.debugBones || comp.debugSlots) {
if (comp.debugBones || comp.debugSlots) {
graphics.clear();
}
@@ -254,7 +254,7 @@ var spineAssembler = {
datas.length = dataId;
}
if (CC_DEBUG && comp.debugBones) {
if (comp.debugBones) {
let bone;
graphics.lineWidth = 5;
graphics.strokeColor = _boneColor;
+2 -1
View File
@@ -67,7 +67,8 @@
"./cocos2d/core/components/CCMask.js",
"./cocos2d/core/renderer/webgl/assemblers/mask-assembler.js",
"./cocos2d/core/renderer/canvas/renderers/mask.js"
]
],
"dependencies": ["Graphics"]
},
{
"name": "Graphics",
+1 -1
View File
@@ -156,7 +156,7 @@ else {
defineMacro('CC_JSB', defined('jsb'));
defineMacro('CC_WECHATGAME', defined('wx') && wx.getSystemInfoSync);
defineMacro('CC_QQPLAY', defined('bk'));
defineMacro('CC_RUNTIME', false);
defineMacro('CC_RUNTIME', 'function' === typeof loadRuntime);
defineMacro('CC_SUPPORT_JIT', !(CC_WECHATGAME || CC_QQPLAY || CC_RUNTIME));
}
-1
View File
@@ -156,7 +156,6 @@ cc.engine = new (cc.Class({
Editor.log = cc.log;
Editor.warn = cc.warn;
Editor.error = cc.error;
Editor.info = cc.info;
Editor.Utils = Editor.Utils || {};
Editor.Utils.UuidCache = {};
+15
View File
@@ -10,3 +10,18 @@ test('dirname', function () {
ok(cc.path.dirname('aa/bb/.github/.gitignore') === 'aa/bb/.github', 'get success');
});
test('basename', function () {
ok(cc.path.basename('aa/bb/cc.js', '.js') === 'cc', 'get success');
ok(cc.path.basename('aa/bb/cc_cc.js','.js') === 'cc_cc', 'get success');
ok(cc.path.basename('aa/bb/cc/') === 'cc', 'get success');
ok(cc.path.basename('D:\\aa\\bb\\cc') === 'cc', 'get success');
ok(cc.path.basename('aa/bb/cc(cc).js', '.js') === 'cc(cc)', 'get success');
ok(cc.path.basename('aa/bb/cc[cc].js', '.js') === 'cc[cc]', 'get success');
ok(cc.path.basename('aa/bb/cc.js/ee.js', '.js') === 'ee', 'get success');
ok(cc.path.basename('aa/bb/.github') === '.github', 'get success');
// ios only, and linux not suggest
ok(cc.path.basename('aa/bb/cc|cc.js', '.js') === 'cc|cc', 'get success');
});