How to slice a 2D texture into multiple rectangles?

Hi!

I need to cut one texture into several rectangles - sprites.
In previous versions of the engine, this could be done something like this:

cc.Class({
 extends: cc.Component,
 properties: {
 texture_pic : cc.SpriteFrame,
 node_cut: cc.Sprite,
 },
 
 onLoad () {
 
 let tx = this.texture_pic.getTexture();
 
 let cutPic = new cc.SpriteFrame(tx);
 
 cutPic.setRect(new cc.Rect(0,0,100,100));
 this.node_cut.spriteFrame = cutPic;
 },
});

I have Cocos Creator 3.6.0, I did not find such methods, I managed to achieve this
the only way: At first, using the Mask, I got a small rectangle, then I rendered to a texture, and then
saved this to a new sprite texture. How can I directly cut a part of a texture and save it to a new sprite
avoiding the mask and render to texture?
I will be grateful for your help!

Solution:

this.sprite.spriteFrame.rect = new Rect(0,0,80,80);

Sorry.

1 Like