Jump to content

Layout engine


user471
 Share

Recommended Posts

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?

 

 

 

Link to comment
Share on other sites

yes, probably best method will be inherinting it from PIXI.Container

DEMO : http://enea.sk/pixijs-demos/horizontal-stack

HorizontalStack = 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;};
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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