Scale9Sprite from sprite sheet exceeds maximum margin

Scale9Sprite from sprite sheet exceeds maximum margin
0

Hi,

I’m trying to create a scale9sprite, this is the code

    var rect = new cc.rect(0, 0, 450, 200);
    var capInsets = new cc.rect(0, 0, 450, 200);

    this.resultBoard = cc.Scale9Sprite.create(res.scale9image, rect, capInsets);
    this.resultBoard.setContentSize(size.x, size.y);   
    this.resultBoard.setPosition(size.x, size.y);
    this.scoreBoardNode.addChild(this.resultBoard);

And i got this error " Rect width exceeds maximum margin: res/scale9image.png"

is the image file 450x200?
This setup also defeats the purpose to scale9, as the 8 edge pieces here are 0x0, as in same to just use a Sprite with setScale.

No, 450x200 is required sprite sheet size.

I am struggling to get proper Scale9Sprite sprite. Can you suggest or give an example of Scale9Sprite sprite?

Thanks for reply.

What is the size of the image? I assume it is smaller, so your capInsets is likely trying to extend beyond the texture.

Yes, it is a small size of 50x50 pixels. I am trying to display scoreboard, the scoreboard size based on players (450x200 is for 4 players and maximum of 6 players, minimum of 2 players).

On this case:
What would be the image file size?
And what suppose to be ‘rest’ and ‘capInsets’ sizes?

capInsets are relative to the texture you are using.

For example:

FOHButtonAspect

Let’s say I want this above image to be Scale9, to where I can have it in any size/aspect ratio…
The reason I would choose to do that, is that I would want to preserve the outer border to not stretch/distort… If I node->setScale(4,1); on that as a regular Sprite, the border on top and sides will not be uniform in width, they would be stretched, and the node would not have the visual I am shooting for that Scale9 can provide.

In that case, if this texture for example is 100x100, and the border is 2px wide, my capInsets would be something like Rect(2,2,96, 96);

Then if I set the Scale9 Size to be, say, 450x200, the inner part would scale uniformly, but the outer perimeter would keep its 2px width.

If I did a capInsets of greater than the original 100x100 texture, I would get the same error you posted above, as the texture does not extend that far.

Hope that clears some of it up… for one last visual, this is what you try to accomplish with Scale9:

vrwy1

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.