Skip to content

Commit

Permalink
new optional argument to return a NineSliceSprite object when using…
Browse files Browse the repository at this point in the history
… `createSpriteFromName`

also adds missing registration into the object pool (not marked as recyclable though)
  • Loading branch information
obiot committed Nov 22, 2021
1 parent 80c07b0 commit 8cb465a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export function boot() {
pool.register("me.Color", Color, true);
pool.register("me.Particle", Particle, true);
pool.register("me.Sprite", Sprite);
pool.register("me.NineSliceSprite", NineSliceSprite);
pool.register("me.Renderable", Renderable);
pool.register("me.Text", Text, true);
pool.register("me.BitmapText", BitmapText);
Expand All @@ -248,6 +249,7 @@ export function boot() {
pool.register("Color", Color, true);
pool.register("Particle", Particle, true);
pool.register("Sprite", Sprite);
pool.register("NineSliceSprite", NineSliceSprite);
pool.register("Renderable", Renderable);
pool.register("Text", Text, true);
pool.register("BitmapText", BitmapText);
Expand Down
7 changes: 4 additions & 3 deletions src/video/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ export class Texture {
* @function
* @param {String} name name of the sprite
* @param {Object} [settings] Additional settings passed to the {@link me.Sprite} contructor
* @return {me.Sprite}
* @param {Boolean} [nineSlice=false] if true returns a 9-slice sprite
* @return {me.Sprite|me.NineSliceSprite}
* @example
* // create a new texture object under the `game` namespace
* game.texture = new me.video.renderer.Texture(
Expand All @@ -435,10 +436,10 @@ export class Texture {
* // set the renderable position to bottom center
* sprite.anchorPoint.set(0.5, 1.0);
*/
createSpriteFromName(name, settings) {
createSpriteFromName(name, settings, nineSlice = false) {
// instantiate a new sprite object
return pool.pull(
"me.Sprite",
nineSlice === true ? "me.NineSliceSprite" : "me.Sprite",
0, 0,
Object.assign({
image: this,
Expand Down

0 comments on commit 8cb465a

Please sign in to comment.