Skip to content

Commit

Permalink
fixed the findCamera problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinCollins committed Dec 18, 2018
1 parent 2373c06 commit baef257
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
25 changes: 20 additions & 5 deletions cocos2d/core/CCNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,10 @@ var Node = cc.Class({
},

set (value) {
// update the groupIndex
this.groupIndex = cc.game.groupList.indexOf(value);
this.groupIndex = this._getParentCullingMask(this);
this._cullingMask = 1 << this.groupIndex;
this.emit(EventType.GROUP_CHANGED, this);
}
},
Expand Down Expand Up @@ -1114,7 +1117,7 @@ var Node = cc.Class({
*/
ctor () {
this._reorderChildDirty = false;

// cache component
this._widget = null;
// fast render component access
Expand All @@ -1138,7 +1141,7 @@ var Node = cc.Class({
this._worldMatDirty = true;

this._eventMask = 0;
this._cullingMask = 1 << this.groupIndex;
this._cullingMask = 1;
},

statics: {
Expand Down Expand Up @@ -1308,6 +1311,9 @@ var Node = cc.Class({

this._updateOrderOfArrival();

// synchronize _cullingMask
this._cullingMask = 1 << this._getParentCullingMask(this);;

let prefabInfo = this._prefab;
if (prefabInfo && prefabInfo.sync && prefabInfo.root === this) {
if (CC_DEV) {
Expand Down Expand Up @@ -1642,12 +1648,12 @@ var Node = cc.Class({
var listeners = useCapture ? this._capturingListeners : this._bubblingListeners;
if (listeners) {
listeners.remove(type, callback, target);

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

}
},

Expand Down Expand Up @@ -1853,7 +1859,7 @@ var Node = cc.Class({
parent = parent.parent;
}
},

/**
* Get all the targets listening to the supplied type of event in the target's bubbling phase.
* The bubbling phase comprises any SUBSEQUENT nodes encountered on the return trip to the root of the tree.
Expand Down Expand Up @@ -3053,6 +3059,15 @@ var Node = cc.Class({
eventManager.pauseTarget(this);
}
},

// traversal the node tree, child cullingMask must keep the same with the parent.
_getParentCullingMask (node) {
let groupIndex = node.groupIndex;
if (groupIndex === 0 && node.parent) {
groupIndex = this._getParentCullingMask(node.parent);
}
return groupIndex;
},
});

/**
Expand Down
11 changes: 1 addition & 10 deletions cocos2d/core/renderer/render-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const POST_RENDER = 1 << 9;
const FINAL = 1 << 10;

let _walker = null;
let _cullingMask = 0;

//
function RenderFlow () {
this._func = init;
this._next = null;
Expand Down Expand Up @@ -107,8 +105,6 @@ _proto._customIARender = function (node) {
};

_proto._children = function (node) {
let cullingMask = _cullingMask;

let parentOpacity = _walker.parentOpacity;
let opacity = (_walker.parentOpacity *= (node._opacity / 255));

Expand All @@ -122,8 +118,7 @@ _proto._children = function (node) {
// Advance the modification of the flag to avoid node attribute modification is invalid when opacity === 0.
c._renderFlag |= worldDirtyFlag;
if (!c._activeInHierarchy || c._opacity === 0) continue;
_cullingMask = c._cullingMask = c.groupIndex === 0 ? cullingMask : 1 << c.groupIndex;


// TODO: Maybe has better way to implement cascade opacity
let colorVal = c._color._val;
c._color._fastSetA(c._opacity * opacity);
Expand All @@ -134,8 +129,6 @@ _proto._children = function (node) {
_walker.parentOpacity = parentOpacity;

this._next._func(node);

_cullingMask = cullingMask;
};

_proto._postUpdateRenderData = function (node) {
Expand Down Expand Up @@ -213,8 +206,6 @@ function getFlow (flag) {


function render (scene) {
_cullingMask = 1 << scene.groupIndex;

if (scene._renderFlag & WORLD_TRANSFORM) {
_walker.worldMatDirty ++;
scene._calculWorldMatrix();
Expand Down

0 comments on commit baef257

Please sign in to comment.