SpriteFrame width and height methods return 2048 after scaling of parent node

Hello, thanks for attention

I have used spriteFrame.width or .height to get original size of spriteFrame and then dynamically calculate indexes to .setScale() on node with this sprite.
But after any scaling of this node, I can not get original width and height of this spriteFrame anymore - it returns me 2048 value instead of those. So if I attaching same spriteFrame to another node - I am not able to make recalculation for another scaling.

At the same time, this spriteFrame can be used on the different nodes with different scales and they does not affect each others scales, so it looks like bug or so.
I come to idea of using of clone() while attaching to Sprite component, so original SpriteFrame will not be affected this way. But it looks weird for me.

So please tell me is it proper behavior of spriteFrame or bug?
Is there another way to get original sizes of it after such operations?

Attaching simple example of how it behave. (CC 3.8.0)

        this.spriteFrame = resources.get('default_sprite/spriteFrame', SpriteFrame);

        const node1 = new Node('Node1');
        node1.parent = find('Canvas');
        const sprite1 = node1.addComponent(Sprite);
        sprite1.spriteFrame = this.spriteFrame;

        const node2 = new Node('Node2');
        node2.parent = find('Canvas');
        node2.setPosition(node1.getPosition().x + 100, node1.getPosition().y);
        const sprite2 = node2.addComponent(Sprite);
        sprite2.spriteFrame = this.spriteFrame; 

        log(this.spriteFrame.width);    //get 40 here

        node1.setScale(0.5, 0.5);
        node2.setScale(1.5, 1.5);

        setTimeout( ()=>{
            log(this.spriteFrame.width);    //get 2048 here and every time after scaling of any node with this.spriteFrame

            //but at the same time, no problems with different scale in different nodes
            const node3 = new Node('Node2');
            node3.parent = find('Canvas');
            node3.setPosition(node2.getPosition().x + 100, node2.getPosition().y);
            const sprite3 = node3.addComponent(Sprite);
            sprite3.spriteFrame = this.spriteFrame; 
        }, 100);

example

You can obtain the original size of the texture by accessing spriteFrame.rect.

图片

Due to the engine’s automatic batching feature, textures smaller than 512x512 will be automatically combined into a 2048x2048 texture.
https://docs.cocos.com/creator/manual/en/advanced-topics/dynamic-atlas.html

You can set the packable property of spriteFrame to false to prevent it from being batched.

1 Like