Skip to content

Instantly share code, notes, and snippets.

@shinhirota
Last active October 13, 2015 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinhirota/f1b12355d0673724f9f8 to your computer and use it in GitHub Desktop.
Save shinhirota/f1b12355d0673724f9f8 to your computer and use it in GitHub Desktop.
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