Monday, November 21, 2022
HomeGame DevelopmentMethods to slice a 2D texture into a number of rectangles? -...

Methods to slice a 2D texture into a number of rectangles? – Cocos Creator


Hello!

I would like to chop one texture into a number of rectangles – sprites.
In earlier variations of the engine, this might be carried out one thing like this:

cc.Class({
 extends: cc.Element,
 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’ve Cocos Creator 3.6.0, I didn’t discover such strategies, I managed to attain this
the one method: At first, utilizing the Masks, I acquired a small rectangle, then I rendered to a texture, after which
saved this to a brand new sprite texture. How can I straight reduce part of a texture and reserve it to a brand new sprite
avoiding the masks and render to texture?
I’ll be glad about your assist!


Answer:

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

Sorry.



1 Like

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments