mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
Merge pull request #951 from knoxHuang/master
fix cc.hide、cc.show、cc.toggleVisibility Web no effect for issues/3698
This commit is contained in:
@@ -75,7 +75,11 @@ cc.ActionInstant = cc.FiniteTimeAction.extend({
|
||||
cc.Show = cc.ActionInstant.extend({
|
||||
|
||||
update:function (dt) {
|
||||
this.target.visible = true;
|
||||
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
|
||||
for (var i = 0; i < _renderComps.length; ++i) {
|
||||
var render = _renderComps[i];
|
||||
render.enabled = true;
|
||||
}
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
@@ -108,7 +112,11 @@ cc.show = function () {
|
||||
cc.Hide = cc.ActionInstant.extend({
|
||||
|
||||
update:function (dt) {
|
||||
this.target.visible = false;
|
||||
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
|
||||
for (var i = 0; i < _renderComps.length; ++i) {
|
||||
var render = _renderComps[i];
|
||||
render.enabled = false;
|
||||
}
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
@@ -141,7 +149,11 @@ cc.hide = function () {
|
||||
cc.ToggleVisibility = cc.ActionInstant.extend({
|
||||
|
||||
update:function (dt) {
|
||||
this.target.visible = !this.target.visible;
|
||||
var _renderComps = this.target.getComponentsInChildren(cc._SGComponent);
|
||||
for (var i = 0; i < _renderComps.length; ++i) {
|
||||
var render = _renderComps[i];
|
||||
render.enabled = !render.enabled;
|
||||
}
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
|
||||
@@ -633,8 +633,8 @@ var Node = cc.Class({
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns all components of supplied type in any of its children.
|
||||
* !#zh 递归查找所有子节点中指定类型的组件。
|
||||
* !#en Returns all components of supplied type in self or any of its children.
|
||||
* !#zh 递归查找自身或所有子节点中指定类型的组件
|
||||
* @method getComponentsInChildren
|
||||
* @param {Function|String} typeOrClassName
|
||||
* @return {Component[]}
|
||||
@@ -645,6 +645,7 @@ var Node = cc.Class({
|
||||
getComponentsInChildren: function (typeOrClassName) {
|
||||
var constructor = getConstructor(typeOrClassName), components = [];
|
||||
if (constructor) {
|
||||
findComponents(this, constructor, components);
|
||||
findChildComponents(this._children, constructor, components);
|
||||
}
|
||||
return components;
|
||||
|
||||
@@ -550,8 +550,8 @@ var Component = cc.Class({
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en Returns the components of supplied type in any of its children using depth first search.
|
||||
* !#zh 递归查找所有子节点中指定类型的组件。
|
||||
* !#en Returns the components of supplied type in self or any of its children using depth first search.
|
||||
* !#zh 递归查找自身或所有子节点中指定类型的组件
|
||||
*
|
||||
* @method getComponentsInChildren
|
||||
* @param {Function|String} typeOrClassName
|
||||
|
||||
@@ -123,6 +123,33 @@ cc.Follow.prototype.update = function(dt) {
|
||||
}
|
||||
};
|
||||
|
||||
cc.Show.prototype.update = function (dt) {
|
||||
var target = this.getTarget();
|
||||
var _renderComps = target._owner.getComponentsInChildren();
|
||||
for (var i = 0; i < _renderComps.length; ++i) {
|
||||
var render = _renderComps[i];
|
||||
render.enabled = true;
|
||||
}
|
||||
};
|
||||
|
||||
cc.Hide.prototype.update = function (dt) {
|
||||
var target = this.getTarget();
|
||||
var _renderComps = target._owner.getComponentsInChildren();
|
||||
for (var i = 0; i < _renderComps.length; ++i) {
|
||||
var render = _renderComps[i];
|
||||
render.enabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
cc.ToggleVisibility.prototype.update = function (dt) {
|
||||
var target = this.getTarget();
|
||||
var _renderComps = target._owner.getComponentsInChildren();
|
||||
for (var i = 0; i < _renderComps.length; ++i) {
|
||||
var render = _renderComps[i];
|
||||
render.enabled = true;
|
||||
}
|
||||
};
|
||||
|
||||
// Special call func
|
||||
cc.callFunc = function (selector, selectorTarget, data) {
|
||||
var callback = function (sender, data) {
|
||||
|
||||
@@ -183,7 +183,7 @@ test('get self components', function () {
|
||||
|
||||
ok(obj.getComponents(MyComponent).length === 3, 'getComponents: can get my component array');
|
||||
ok(obj.getComponentInChildren(MyComponent) === comp, 'getComponentInChildren: can get my component in children');
|
||||
ok(obj.getComponentsInChildren(MyComponent).length === 2, 'getComponentsInChildren: can get my components in children');
|
||||
ok(obj.getComponentsInChildren(MyComponent).length === 5, 'getComponentsInChildren: can get my components in children and self');
|
||||
|
||||
cc.js.unregisterClass(MyComponent);
|
||||
});
|
||||
@@ -205,7 +205,26 @@ test('should not include self component', function () {
|
||||
obj1.parent = obj;
|
||||
|
||||
ok(obj.getComponentInChildren(MyComponent) === null, 'getComponentInChildren should not include self component');
|
||||
ok(obj.getComponentsInChildren(MyComponent).length === 0, 'getComponentsInChildren should not include self component');
|
||||
|
||||
cc.js.unregisterClass(MyComponent);
|
||||
});
|
||||
|
||||
test('should include self component', function () {
|
||||
var MyComponent = cc.Class({
|
||||
name: 'MyComponent',
|
||||
extends: cc.Component
|
||||
});
|
||||
|
||||
var obj = new cc.Node("New Node");
|
||||
cc.director.getScene().addChild(obj);
|
||||
obj.addComponent(MyComponent);
|
||||
obj.addComponent(MyComponent);
|
||||
obj.addComponent(MyComponent);
|
||||
|
||||
var obj1 = new cc.Node("New Node 1");
|
||||
obj1.parent = obj;
|
||||
|
||||
ok(obj.getComponentsInChildren(MyComponent).length === 3, 'getComponentsInChildren should include self component');
|
||||
|
||||
cc.js.unregisterClass(MyComponent);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user