Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
pp.Scale9SpriteTiled = cc.Scale9Sprite.extend({
_updatePositions: function () {
this._super();
this._addChildInsteadOfScaling(this._top);
this._addChildInsteadOfScaling(this._bottom);
this._addChildInsteadOfScaling(this._left);
this._addChildInsteadOfScaling(this._right);
this._addChildInsteadOfScaling(this._centre);
},
_addChildInsteadOfScaling: function (sprite) {
for (var ix = 0; ix < sprite.scaleX; ix ++) {
for (var iy = 0; iy < sprite.scaleY; iy++) {
var rect = sprite.getTextureRect();
if (ix + 1 > sprite.scaleX) {
rect.width = rect.width * (sprite.scaleX - ix);
}
if (iy + 1 > sprite.scaleY) {
rect.height = rect.height * (sprite.scaleY - iy);
}
var aTile = new cc.Sprite(sprite.texture, rect);
aTile.attr({
x: sprite.x + sprite.width*ix,
y: sprite.y + sprite.height*iy,
ignoreAnchor: true
});
this.addChild(aTile, -1);
}
}
sprite.visible = false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment