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

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.