Saturday, November 19, 2022
HomeGame DevelopmentLearn how to slice a 2D texture into a number of rectangles?...

Learn how 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 could possibly be executed 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 realize this
the one approach: At first, utilizing the Masks, I bought a small rectangle, then I rendered to a texture, after which
saved this to a brand new sprite texture. How can I instantly reduce part of a texture and reserve it to a brand new sprite
avoiding the masks and render to texture?
I’ll be thankful for your assist!


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments