POSIX Posted March 8, 2020 Share Posted March 8, 2020 Is it possible to change the texture? Thank you in advance! Link to comment Share on other sites More sharing options...
POSIX Posted March 8, 2020 Author Share Posted March 8, 2020 Code: TimeLine.to(elevator, 1, { pixi: { x: elevator.x + 200, texture: loader.resources['elevator2'].texture }}); Link to comment Share on other sites More sharing options...
Rodrigo Posted March 8, 2020 Share Posted March 8, 2020 Hi and welcome to the GreenSock forums. Texture is a property of the Sprite display object and can be changed manually using code, I've done that in the past without any issues. There are a couple of things you need to keep in mind though, first the texture's base texture has to be ready by the time the sprite is updated (using the base texture's instance loaded method), and second I'm not sure it can be done in the regular GSAP fashion, meaning that is not something you want or need to update on every GSAP tick. Perhaps use an event callback like onStart or just a regular function to update the texture. Finally make sure that the base texture and hence the texture itself do exist before updating the sprite, since the error stems from this: http://pixijs.download/release/docs/packages_sprite_src_Sprite.js.html#line201 More specifically line 215. Perhaps @OSUblake can shed some light into this, since He is the PIXI master of this realms Happy Tweening!!! 5 Link to comment Share on other sites More sharing options...
OSUblake Posted March 9, 2020 Share Posted March 9, 2020 On 3/8/2020 at 11:47 AM, Rodrigo said: Perhaps @OSUblake can shed some light into this, since He is the PIXI master of this realms Nah, you covered it pretty well. GSAP can really only animate number values and string values with number or color values in it. A texture is a complex object. If you need to change the texture, then you need to do it inside a callback. 4 Link to comment Share on other sites More sharing options...
_Ro Posted July 14, 2022 Share Posted July 14, 2022 Yes, it is very much possible to swap a pixi sprite's texture with gsap. I was able to swap the texture of a sprite with a canvas this way: const dataUrl = canvas.toDataURL('png'); const base = new PIXI.BaseTexture(dataUrl); const newTexture = new PIXI.Texture(base); gsap.set(resource, { pixi: { texture: newTexture} }); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now