Skip to content

Commit

Permalink
Sync branch v2.3.0 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
cocos-robot authored May 23, 2019
2 parents 79f17ca + a0f537f commit cbda683
Show file tree
Hide file tree
Showing 33 changed files with 664 additions and 463 deletions.
5 changes: 3 additions & 2 deletions cocos2d/core/3d/skeleton/CCSkeletonAnimationClip.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ let SkeletonAnimationClip = cc.Class({
let matrix;
let EPSILON = 10e-5;

if (node !== rootNode) {
let props = paths[node.path].props;
let path = paths[node.path];
if (node !== rootNode && path) {
let props = path.props;
for (let prop in props) {
let frames = props[prop];
for (let i = 0; i < frames.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions cocos2d/core/CCDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,11 +963,11 @@ cc.Director.prototype = {
},

__fastOn: function (type, callback, target) {
this.add(type, callback, target);
this.on(type, callback, target);
},

__fastOff: function (type, callback, target) {
this.remove(type, callback, target);
this.off(type, callback, target);
},
};

Expand Down
44 changes: 23 additions & 21 deletions cocos2d/core/CCNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ var LocalDirtyFlag = cc.Enum({
/**
* !#en The event type supported by Node
* !#zh Node 支持的事件类型
* @enum Node.EventType
* @class Node.EventType
* @static
* @namespace Node
*/
// Why EventType defined as class, because the first parameter of Node.on method needs set as 'string' type.
var EventType = cc.Enum({
/**
* !#en The event type for touch start event, you can use its value directly: 'touchstart'
Expand Down Expand Up @@ -552,7 +553,7 @@ let NodeDefines = {
_contentSize: cc.Size,
_anchorPoint: cc.v2(0.5, 0.5),
_position: cc.Vec3,
_scale: cc.v3(1, 1, 1),
_scale: cc.Vec3.ONE,
_eulerAngles: cc.Vec3,
_skewX: 0.0,
_skewY: 0.0,
Expand Down Expand Up @@ -1559,7 +1560,6 @@ let NodeDefines = {
*/
once (type, callback, target, useCapture) {
let forDispatch = this._checknSetupSysEvent(type);
let eventType_hasOnceListener = '__ONCE_FLAG:' + type;

let listeners = null;
if (forDispatch && useCapture) {
Expand All @@ -1569,17 +1569,7 @@ let NodeDefines = {
listeners = this._bubblingListeners = this._bubblingListeners || new EventTarget();
}

let hasOnceListener = listeners.hasEventListener(eventType_hasOnceListener, callback, target);
if (!hasOnceListener) {
let self = this;
let onceWrapper = function (arg1, arg2, arg3, arg4, arg5) {
self.off(type, onceWrapper, target);
listeners.remove(eventType_hasOnceListener, callback, target);
callback.call(this, arg1, arg2, arg3, arg4, arg5);
};
this.on(type, onceWrapper, target);
listeners.add(eventType_hasOnceListener, callback, target);
}
listeners.once(type, callback, target);
},

_onDispatch (type, callback, target, useCapture) {
Expand All @@ -1603,10 +1593,15 @@ let NodeDefines = {
}

if ( !listeners.hasEventListener(type, callback, target) ) {
listeners.add(type, callback, target);
listeners.on(type, callback, target);

if (target && target.__eventTargets)
target.__eventTargets.push(this);
if (target) {
if (target.__eventTargets) {
target.__eventTargets.push(this);
} else if (target.node && target.node.__eventTargets) {
target.node.__eventTargets.push(this);
}
}
}

return callback;
Expand Down Expand Up @@ -1690,10 +1685,14 @@ let NodeDefines = {
else {
var listeners = useCapture ? this._capturingListeners : this._bubblingListeners;
if (listeners) {
listeners.remove(type, callback, target);
listeners.off(type, callback, target);

if (target && target.__eventTargets) {
js.array.fastRemove(target.__eventTargets, this);
if (target) {
if (target.__eventTargets) {
js.array.fastRemove(target.__eventTargets, this);
} else if (target.node && target.node.__eventTargets) {
js.array.fastRemove(target.node.__eventTargets, this);
}
}
}

Expand Down Expand Up @@ -1850,7 +1849,10 @@ let NodeDefines = {
}

this._updateWorldMatrix();
mat4.invert(_mat4_temp, this._worldMatrix);
// If scale is 0, it can't be hit.
if (!mat4.invert(_mat4_temp, this._worldMatrix)) {
return false;
}
vec2.transformMat4(testPt, cameraPt, _mat4_temp);
testPt.x += this._anchorPoint.x * w;
testPt.y += this._anchorPoint.y * h;
Expand Down
6 changes: 6 additions & 0 deletions cocos2d/core/assets/material/CCMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import Effect from '../../../renderer/core/effect';
import murmurhash2 from './murmurhash2_gc';
import utils from './utils';

/**
* !#en Material Asset.
* !#zh 材质资源类。
* @class Material
* @extends Asset
*/
let Material = cc.Class({
name: 'cc.Material',
extends: Asset,
Expand Down
3 changes: 1 addition & 2 deletions cocos2d/core/components/CCLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,12 @@ let Label = cc.Class({
let material = this.sharedMaterials[0];

if (!material) {
material = Material.getInstantiatedBuiltinMaterial('sprite', this);
material = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
}
else {
material = Material.getInstantiatedMaterial(material, this);
}

material.define('USE_TEXTURE', true);
material.setProperty('texture', this._frame._texture);
this.setMaterial(0, material);
}
Expand Down
11 changes: 7 additions & 4 deletions cocos2d/core/components/CCMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ let Mask = cc.Class({
// Init material
let material = this.sharedMaterials[0];
if (!material) {
material = Material.getInstantiatedBuiltinMaterial('sprite', this);
material = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
}
else {
material = Material.getInstantiatedMaterial(material, this);
Expand All @@ -392,11 +392,11 @@ let Mask = cc.Class({
}

if (!this._enableMaterial) {
this._enableMaterial = Material.getInstantiatedBuiltinMaterial('sprite', this);
this._enableMaterial = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
}

if (!this._exitMaterial) {
this._exitMaterial = Material.getInstantiatedBuiltinMaterial('sprite', this);
this._exitMaterial = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
let passes = this._exitMaterial.effect.getDefaultTechnique().passes;
for (let i = 0; i < passes.length; i++) {
passes[i].setStencilEnabled(gfx.STENCIL_DISABLE);
Expand Down Expand Up @@ -480,7 +480,10 @@ let Mask = cc.Class({
testPt = _vec2_temp;

node._updateWorldMatrix();
mat4.invert(_mat4_temp, node._worldMatrix);
// If scale is 0, it can't be hit.
if (!mat4.invert(_mat4_temp, node._worldMatrix)) {
return false;
}
vec2.transformMat4(testPt, cameraPt, _mat4_temp);
testPt.x += node._anchorPoint.x * w;
testPt.y += node._anchorPoint.y * h;
Expand Down
3 changes: 1 addition & 2 deletions cocos2d/core/components/CCMotionStreak.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,12 @@ var MotionStreak = cc.Class({

let material = this.sharedMaterials[0];
if (!material) {
material = Material.getInstantiatedBuiltinMaterial('sprite', this);
material = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
}
else {
material = Material.getInstantiatedMaterial(material, this);
}

material.define('USE_TEXTURE', true);
material.setProperty('texture', this._texture);

this.setMaterial(0, material);
Expand Down
18 changes: 18 additions & 0 deletions cocos2d/core/components/CCRenderComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ let RenderComponent = cc.Class({
type: Material,
},

/**
* !#en The materials used by this render component.
* !#zh 渲染组件使用的材质。
* @property {[Material]} sharedMaterials
*/
sharedMaterials: {
get () {
return this._materials;
Expand Down Expand Up @@ -156,6 +161,12 @@ let RenderComponent = cc.Class({
}
},

/**
* !#en Get the material by index.
* !#zh 根据指定索引获取材质
* @method getMaterial
* @param {Number} index
*/
getMaterial (index) {
if (index < 0 || index >= this._materials.length) {
return null;
Expand All @@ -172,6 +183,13 @@ let RenderComponent = cc.Class({
return this._materials[index];
},

/**
* !#en Set the material by index.
* !#zh 根据指定索引设置材质
* @method setMaterial
* @param {Number} index
* @param {Material} material
*/
setMaterial (index, material) {
this._materials[index] = material;
if (material) {
Expand Down
3 changes: 1 addition & 2 deletions cocos2d/core/components/CCSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,12 @@ var Sprite = cc.Class({
// make sure material is belong to self.
let material = this.sharedMaterials[0];
if (!material) {
material = Material.getInstantiatedBuiltinMaterial('sprite', this);
material = Material.getInstantiatedBuiltinMaterial('2d-sprite', this);
}
else {
material = Material.getInstantiatedMaterial(material, this);
}

material.define('USE_TEXTURE', true);
material.setProperty('texture', spriteFrame.getTexture());

this.setMaterial(0, material);
Expand Down
30 changes: 14 additions & 16 deletions cocos2d/core/event/event-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,27 @@
THE SOFTWARE.
****************************************************************************/

var js = cc.js;
var CallbacksHandler = require('../platform/callbacks-invoker').CallbacksHandler;
const js = cc.js;
const CallbacksInvoker = require('../platform/callbacks-invoker');

// Extends CallbacksHandler to handle and invoke event callbacks.
// Extends CallbacksInvoker to handle and invoke event callbacks.
function EventListeners () {
CallbacksHandler.call(this);
CallbacksInvoker.call(this);
}
js.extend(EventListeners, CallbacksHandler);
js.extend(EventListeners, CallbacksInvoker);

EventListeners.prototype.invoke = function (event, captureListeners) {
var key = event.type;
var list = this._callbackTable[key];
EventListeners.prototype.emit = function (event, captureListeners) {
let key = event.type;
const list = this._callbackTable[key];
if (list) {
var rootInvoker = !list.isInvoking;
let rootInvoker = !list.isInvoking;
list.isInvoking = true;

var callbacks = list.callbacks;
var targets = list.targets;
for (var i = 0, len = callbacks.length; i < len; ++i) {
var callback = callbacks[i];
if (callback) {
var target = targets[i] || event.currentTarget;
callback.call(target, event, captureListeners);
const infos = list.callbackInfos;
for (let i = 0, len = infos.length; i < len; ++i) {
const info = infos[i];
if (info && info.callback) {
info.callback.call(info.target, event, captureListeners);
if (event._propagationImmediateStopped) {
break;
}
Expand Down
Loading

0 comments on commit cbda683

Please sign in to comment.