hashi Posted June 2, 2014 Share Posted June 2, 2014 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;orsprite.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? Quote Link to comment Share on other sites More sharing options...
GNUton Posted June 4, 2014 Share Posted June 4, 2014 In order to keep the sprite in the same position you may want set the anchor into the middle of your sprite before flipping.Mysprite.anchor.x = 0.5 //50% of its width 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.