vesantpro Posted March 3, 2017 Share Posted March 3, 2017 I have image with 10 different animations and 10 frames by each. On stage i have for example set of 15 diffeent objects with animation. From time to time i have to change set of animation to another.One way to do this is to delete objects and create them once more with needed sprite animation. var moveClip1 = createClip(5); createClip: function (symbolIndex) { var image = this.game.getImage('images.symbols'); var base = new PIXI.BaseTexture(image); var textures = []; for (j = 0; j < steps; j++) tempTexture = new PIXI.Texture(base, { x: this.game.symbolHeight * j, y: this.game.symbolWidth * symbolIndex, width: this.game.symbolHeight, height: this.game.symbolWidth }); textures.push(tempTexture); symbolClip= new PIXI.extras.AnimatedSprite(textures); } return (symbolClip) } Is it posible to change texture in existing object moveClip1 without recrete the object? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 3, 2017 Share Posted March 3, 2017 That's one of common use-cases (character goes up,down,left,right) , and yes, you can just assign different array to "animatedSprite.textures", it will work. Quote Link to comment Share on other sites More sharing options...
vesantpro Posted March 6, 2017 Author Share Posted March 6, 2017 Would you mind to help me? I have object moveClip1, and i have to change sprite sheet in it without deleting this object. Something like this: moveClip1= new PIXI.extras.AnimatedSprite(oldTextures); moveClip1.textures =newTextures; moveClip1.textures.update();For exapmlpe in case of simple Pixi sprite we have method to update texture : sprite1 = new PIXI.Sprite(oldTexture); newTexture = new PIXI.Texture(baseTexture); sprite1.texture = newTexture; sprite1.texture.update(); Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 6, 2017 Share Posted March 6, 2017 "textures" is just JS array. You dont have to update it. Quote Link to comment Share on other sites More sharing options...
vesantpro Posted March 7, 2017 Author Share Posted March 7, 2017 Thank you Ivan, it realy works! I just asign new textures aray to existing AnimatedSprite. Also spend some problems with webGL context. After 8-10 texture changes i 'm geting Chrome console error. (W10 64bit, Chome 56 64bit, Video GeForce GTX 650 with last driver) GL_INVALID_OPERATION : glGenSyncTokenCHROMIUM: fence sync must be flushed before generating sync token WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 9, 2017 Share Posted March 9, 2017 Did you justt run out of videomemory? I hope you dont load textures each time? 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.