Monday, February 28, 2011

9-scale resizing

If You want to create component properly scalable remember about resizing shapes. Problem occurs during resizing for example rectangles. Border of 2 pixels thick becomes really big. Because object is resized as-is proportionally with content and graphic.
Here is the proof:

To avoid this problem You should use 9-scale. This property (officialy named scale9Grid) is avaiable in Movieclips, Sprites and so on. Here is example of code how to use it:

var background3 = new Sprite();
background3.graphics.lineStyle(2, 0xd61e31);
background3.graphics.beginFill(0xFFFFFF, 1);
background3.graphics.drawRect(0, 0, 40, 40);
background3.graphics.endFill();


//here comes 9-scaling
var grid:Rectangle = new Rectangle(5, 5, 30, 30);
background3.scale9Grid = grid;


Rectangle that is created above creates 9 regions in our object (which also is rectangle shaped). Picture below shows regions. Points A(5,5) and B(30,30) shows coordinates of lines which are regions borders.


Those 9 regions can be grouped to 4 types. Each type is scaled in different way:
  • corners - four corners are not scaled. They are constant
  • long vertical sides - middle-left region and middle-right regions are scaled only in Y axis
  • long horizontal sides - center-top and center-bottom regions are scaled only in X axis
  • middle-center - this region is scaled in both directions

Here is description from API


2 comments:

  1. Anonymous6/24/2013

    Your point B is incorrect. It should be B(35,35):

    * The scale9Grid rectangle is offset at (5,5) and has width (30, 30).
    * The top-left corner A is the origin at (5,5)
    * The bottom-right corner B is at the origin + width/height: (5+30, 5+30)
    * The top-left margin is 5px, when B is at (35,35) the bottom-right margin is 5px and everything is symmetrical.

    ReplyDelete
  2. Anonymous2/03/2022

    Vimeo Vimeo Video Slot – Play Online Free. (No Download)
    Vimeo is one of the leading providers of educational and interactive youtube to mp3 virtual sports content for entertainment Videos: VimeoVideos

    ReplyDelete