Display segment of Sprite

Hi,

Been trying to figure out best way to handle this and tbh the documentation is very limited on explanation of the api.

What I am trying to do is display a segment of a sprite. I have decided to do my own clipping as using the stencil clipping is very processor expensive and does not work on some browsers.

If I have a sprite which is 128x128 in size. I am displaying it at coords 100x100. I am adding a scale onto this sprite which is desiredSize/spriteSize. Now I want to…for example… say ok the sprite is half over my clipping boundary… eg…
|--------|
------| sprite |-------
| |--------| |

What is the best way to achieve this with the sprite api?

I have tested using _setTextureCoords to specify the segment of the sprite I want.
Adjusted the new coords of the sprite
And then tried using scale etc to get a result of only the bottom half of the sprite appearing but I am getting strange results.

Is there any method to specify to the sprite that I only want to occupy x,y,w,h area of the screen?
As I said the API is very limited in documentation and I have scanned through the Sprite js code but I cannot figure the best approach for this.

Thanks

Hi, @pjdavis1970

Sorry for the lack of documentation, we are tring to provide more and more recently.
For your question, assume that you want to use the area of the texture which start at (50, 50) and have size of (32, 32)
You can try sprite.setTextureRect( cc.rect(50, 50, 32, 32) ); and that should be enough to clip your texture. This can also be changed at runtime.

Huabin