Akis Posted November 22, 2013 Share Posted November 22, 2013 Hi, 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 Quote Link to comment Share on other sites More sharing options...
Akis Posted November 22, 2013 Author Share Posted November 22, 2013 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.onTextureUpdateOk, 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... Quote Link to comment Share on other sites More sharing options...
Akis Posted November 22, 2013 Author Share Posted November 22, 2013 Ok, I resolved this by manually listening to the update eventvar 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. Quote Link to comment Share on other sites More sharing options...
Akis Posted November 22, 2013 Author Share Posted November 22, 2013 Even with a cache texture, it's weird to have to do this.sprite.setTexture(PIXI.TextureCache['frame1']);sprite.onTextureUpdate(); Quote Link to comment Share on other sites More sharing options...
Mat Groves Posted November 25, 2013 Share Posted November 25, 2013 HI there Akis! Thanks for sharing your issue. This indeed looks like a bug :/ It should be that onTextureUpdate gets called automatically, but looks like something is not ticking over correctly there. I will make sure to take a look into that for you. Cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.