PDA

View Full Version : CompositeSprite destruction



LesJ
24 Jan 2012, 1:36 PM
I do a lot of work with composite sprites. I simplified the current destroy() method, which also should be a little faster. I just skipped the getCount() call, which is not needed since first() will return null if there are no more sprites to be destroyed.



// current
destroy: function(){
var me = this,
surface = me.getSurface(),
item;

if (surface) {
while (me.getCount() > 0) {
item = me.first();
me.remove(item);
surface.remove(item);
}
}
me.clearListeners();
}

// modified
destroy: function(){
var me = this,
surface = me.getSurface(),
item;

if (surface) {
while (item = me.first()) {
me.remove(item);
surface.remove(item);
}
}
me.clearListeners();
}

LesJ
12 Feb 2012, 5:33 AM
Can we turn this into a ticket? This small change will improve performance and reduce code size.

LesJ
13 Feb 2012, 6:33 AM
... and the 2nd param in the call to surface.remove is missing (http://www.sencha.com/forum/showthread.php?167738-CompositeSprite-incomplete-destroy) (still not fixed as of B2)

Let's create a ticket, thank you ;)



// modified
destroy: function(){
var me = this,
surface = me.getSurface(),
item;

if (surface) {
while (item = me.first()) {
me.remove(item);
surface.remove(item, true);
}
}
me.clearListeners();
}

LesJ
13 Feb 2012, 6:58 AM
I overrode the CompositeSprite.destroy method. Now that I'm actually destroying the sprites it takes a lot longer to destroy the group. This is bad, but we need to properly destroy the sprites.


Ext.define('wag.override.draw.CompositeSprite', {
override: 'Ext.draw.CompositeSprite',

destroy: function () {
var me = this,
surface = me.getSurface(),
item;

if (surface) {
while (item = me.first()) {
me.remove(item);
surface.remove(item, true);
}
}
me.clearListeners();
}
});