user471 Posted January 5, 2016 Share Posted January 5, 2016 Is there any library which could do something like this.I have three sprites and I want to place them horizontally with some margin.So, instead of calculating their positions manually, I want to do something like this.var stack = new HorizontalStack();stack.margin = 10;stack.addChild(sprite1);stack.addChild(sprite2);stack.addChild(sprite3);If such thing doesn't exist, what would be the best way to implement this?I guess I can inherit HorizontalStack from Container.What would be the best place to recalculate children positions? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted January 5, 2016 Share Posted January 5, 2016 There's no reflow process, so you have to add it yourself. Its better to separate it from rendering and updateTransform(). Also, dont forget that container bounds are calculated based on childrens. Quote Link to comment Share on other sites More sharing options...
bubamara Posted January 5, 2016 Share Posted January 5, 2016 yes, probably best method will be inherinting it from PIXI.ContainerDEMO : http://enea.sk/pixijs-demos/horizontal-stackHorizontalStack = function(margin) { PIXI.Container.call(this); this.margin = margin || 20; this.lastChildX = null;};HorizontalStack.prototype = Object.create(PIXI.Container.prototype);HorizontalStack.prototype.constructor = HorizontalStack;HorizontalStack.prototype.add = function(sprite) { if (this.lastChildX !== null) { sprite.position.x = this.lastChildX + this.margin; } else { sprite.position.x = 0; } sprite.position.y = 0; this.addChild(sprite); this.lastChildX = sprite.position.x;}; Quote Link to comment Share on other sites More sharing options...
user471 Posted January 5, 2016 Author Share Posted January 5, 2016 thanks 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.