Jump to content

Resize a texture in a sprite


Recommended Posts



In my project, I created a sprite using a "default" texture, then later I'd like to replace the texture by another one but this one could have a different size than the default, so I need a way to resize the texture. Could you tell me the way to do it?


I create my new texture using PIXI.Texture.fromImage and then I switch the texture with setTexture

Link to comment
Share on other sites

This function doesn't seem to be fired when I update the texture...

/** * When the texture is updated, this event will fire to update the scale and frame */PIXI.Sprite.prototype.onTextureUpdate

Ok, I see the sprite listens the update event of the texture, but if I change the texture with setTexture, it will never listen the events from the new texture...

Link to comment
Share on other sites

Ok, I resolved this by manually listening to the update event

var that = this,    texture = PIXI.Texture.fromImage(imageUrl, true);var textureUpdated = function () {    texture.off('update', textureUpdated);    // rescale the image    that.mSprite.onTextureUpdate(); };texture.on( 'update', textureUpdated);this.mSprite.setTexture(texture);

In my case, I won't exactly use onTextureUpdate as I need to keep the ratio of the image when I scale it. But I think the lib should already do that by default when we change the texture.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...