Permalink
Browse files
new Container `onChildChange` callback for when a child is added or r…
- Loading branch information...
Showing
with
31 additions
and
3 deletions.
-
+2
−1
CHANGELOG
-
+1
−1
package.json
-
+17
−1
src/renderable/container.js
-
+11
−0
tests/spec/container-spec.js
|
|
@@ -1,6 +1,7 @@ |
|
|
Version History
|
|
|
---------------
|
|
|
-5.0.2
|
|
|
+5.1.0
|
|
|
+* Container : new `onChildChange` callback for when a child is added or removed
|
|
|
|
|
|
5.0.1
|
|
|
* Input : fix a regression with bindPointer
|
|
|
|
|
@@ -1,6 +1,6 @@ |
|
|
{
|
|
|
"name": "melonjs",
|
|
|
- "version": "5.0.2",
|
|
|
+ "version": "5.1.0",
|
|
|
"description": "MelonJS Game Engine",
|
|
|
"homepage": "http://www.melonjs.org/",
|
|
|
"repository": {
|
|
|
|
@@ -95,6 +95,17 @@ |
|
|
*/
|
|
|
this.autoDepth = true;
|
|
|
|
|
|
+ /**
|
|
|
+ * a callback to be extended, triggered when a child is added or removed
|
|
|
+ * @name onChildChange
|
|
|
+ * @memberOf me.Container
|
|
|
+ * @function
|
|
|
+ * @param {Number} index added or removed child index
|
|
|
+ */
|
|
|
+ this.onChildChange = function (/* index */) {
|
|
|
+ // to be extended
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* Used by the debug panel plugin
|
|
|
* @ignore
|
|
@@ -158,6 +169,8 @@ |
|
|
child.onActivateEvent();
|
|
|
}
|
|
|
|
|
|
+ this.onChildChange.call(this, this.children.length - 1);
|
|
|
+
|
|
|
return child;
|
|
|
},
|
|
|
|
|
@@ -192,6 +205,8 @@ |
|
|
child.onActivateEvent();
|
|
|
}
|
|
|
|
|
|
+ this.onChildChange.call(this, index);
|
|
|
+
|
|
|
return child;
|
|
|
}
|
|
|
else {
|
|
@@ -546,6 +561,7 @@ |
|
|
this.children.splice(childIndex, 1);
|
|
|
child.ancestor = undefined;
|
|
|
}
|
|
|
+ this.onChildChange.call(this, childIndex);
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -801,7 +817,7 @@ |
|
|
|
|
|
for (var i = this.children.length, obj; i--, (obj = this.children[i]);) {
|
|
|
if (obj.isRenderable) {
|
|
|
-
|
|
|
+
|
|
|
isFloating = obj.floating === true;
|
|
|
|
|
|
if ((obj.inViewport || isFloating)) {
|
|
|
|
@@ -57,5 +57,16 @@ describe("me.Container", function () { |
|
|
});
|
|
|
expect(counter).toEqual(2);
|
|
|
});
|
|
|
+ it("onChildChange callback", function () {
|
|
|
+ counter = 0;
|
|
|
+ container.onChildChange = function (index) {
|
|
|
+ // just count how many times this one is called
|
|
|
+ counter ++;
|
|
|
+ };
|
|
|
+ container.addChild(new me.Renderable(50, 50, 100, 100));
|
|
|
+ container.addChild(new me.Renderable(100, 100, 100, 100));
|
|
|
+ container.removeChildNow(container.getChildAt(0));
|
|
|
+ expect(counter).toEqual(3);
|
|
|
+ });
|
|
|
});
|
|
|
});
|
0 comments on commit
5077eb1