Friday, 13 September 2013

Altering the Kinetic group childrens array

Altering the Kinetic group childrens array

Straight forward: How do I change the position of Kinetic.Group children
in the array? It is really important for me that I can alter the array and
the position of each children.
I tried to add a child with Array.splice on a specific position but
library crashed. So I sticked to the native .add() function, took the
child from the end of the array and spliced it on first place afterwards:
mapTilesContainer.add(image);
var tempChild =
mapTilesContainer.children[mapTilesContainer.children.length - 1];
// delete it from the last place
mapTilesContainer.children.splice(mapTilesContainer.children.length - 1, 1);
// add it to the first place
mapTilesContainer.children.splice(0, 0, tempChild);
which somehow works, but if I then want to destroy a child regularly with
.destroy() it crashes again:
mapTilesContainer.children[8].destroy();
Telling me: Uncaught TypeError: Cannot call method 'getLayer' of undefined
in kinetic.js:2
Adding and destroying without messing with splice works though. Any ideas?

No comments:

Post a Comment