Sign in to follow this  
Akis

Change width/height of sprite without texture scaling?

Recommended Posts

How can I change the texture width/height but without any scaling of the texture in it? Basically, I just want to "cut" my sprite texture.

 

If I update the 'width' or 'height' property, this will change the scaling. If I change the '_width' or '_height', it won't change anything :/

 

 

 

//edit: Hmm it seems I can achieve it by modifying the texture instead of the sprite.. The issue is that it will definitely altered the texture so if others sprites use the same texture, it won't work as expected :s

Share this post


Link to post
Share on other sites

I think if you want to crop your texture, you need to make a new one:

var texture = PIXI.Texture.fromImage('sprite.png');var sprite = new PIXI.Sprite(texture);var texture2 = new PIXI.Texture(texture, new PIXI.Rectangle(10, 10, 50, 50));sprite.setTexture(texture2);

Share this post


Link to post
Share on other sites

Basically what you are trying to do is change the frame of the texture (the frame is a Rectangle object that defines the area of a BaseTexture that a Texture represents). What enpu's code does is create a new texture with the same base texture, but a different frame.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.