Jump to content

What is the best way to set a rotation center of Container?


ptol
 Share

Recommended Posts

With sprite it's possible to use anchor, but container only has pivot. So I wrote something like this. Is it a correct approach?

The only disadvantage is I need to update it after any bounds changes, is there any simple way to improve it?

 

var px = PIXI;
Object.defineProperty(px.Container.prototype, "pivotAnchor", {
	get: function() {
		var bounds = this.getLocalBounds();
		var x = 0;
		var y = 0;
		if(bounds.width > 0){
			x = this.pivot.x/bounds.width;
		}
		if(bounds.height > 0){
			y = this.pivot.y/bounds.height;
		}
		return new px.Point(x,y);
	},
	set: function(v){
		var bounds = this.getLocalBounds();
		this.pivot.x = bounds.width*v.x;
		this.pivot.y = bounds.height*v.y;
	}});

container.pivotAnchor = new px.Point(0.5, 0.5);

l

 

 

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