Jump to content

Flipping by Scalling Sprite problem


hashi
 Share

Recommended Posts

Hi

 

It's my first post here, glad to join you guys. Anyway I try to flip sprite(or just texture) horizontally, these are the only ways I found:

sprite.scale.x = -1;

or

sprite.width = sprite.width * -1;

but both of them are buggy ways (I don't mean that scalling has a bug). They of course flip sprite horizontally, but also move it to the left of sprite.width pixels.

 

I don't really like the solution that we could keep state for example:

sprite.flippedH = true; //user defined variable;

 

so then we can move it to the right preventing displacement of sprite.

 

Is there something to just flip it without changing displaying position?

 

EDIT:

 

Is this the only way we can do it?

//extending PIXI.Sprite classPIXI.Sprite.prototype.__defineGetter__("flippedH", function() {	return (this._flippedH === true);});PIXI.Sprite.prototype.__defineSetter__("flippedH", function(val) {	if ( val != (this._flippedH===true) ) {		if ( val ) {			this.anchor.x = 0.9; //not 1, because then 1px is out of place to right side		}		else {			this.anchor.x = 0;		}                this.scale.x *= -1;	}	this._flippedH = val;});

it uses scale and anchor vars, Why it's bad way to achieve it? Because when we use anchor or scalling things to do something different that this, we need to care about negative value of scale and occupied field of anchor.

 

Any ideas?

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