View on GitHub

Scale9image

Optimized scale9Grid image for starling

Download this project as a .zip file Download this project as a tar.gz file

Exemples :

Base texture :

Getting started :

Create your Scale9Image with a texture and the rectangle of your 9grid and... it's done... 60fps and only 1 draw calls


var text:Texture = Texture.fromBitmap(new bitmap());
image = new Scale9Image(text, new Rectangle(25,25,35,35));
addChild(image);
Starling.current.nativeStage.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void
{
  image.width = e.stageX;
  image.height = e.stageY;
});
        

Multime Images :

you can create multiple Scale9Image from a texture without adding new drawCalls

var text:Texture = Texture.fromBitmap(new bitmap());
var text2:Texture = Texture.fromTexture(text, new Rectangle(10,10,80,80), null);

image = new Scale9Image(text2, new Rectangle(15,15,35,35));
addChild(image);

image2 = new Scale9Image(text2, new Rectangle(15,15,35,35));
image2.x = 100;
addChild(image2);

Starling.current.nativeStage.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void
{
  image.width = e.stageX;
  image.height = e.stageY;
  image2.width = e.stageX;
  image2.height = e.stageY;
});

Texture Atlas :

you can create a Scale9Image from a part of a texture without adding new drawCalls

var text:Texture = Texture.fromBitmap(new bitmap());
var text2:Texture = Texture.fromTexture(text, new Rectangle(10,10,80,80), null);

image = new Scale9Image(text2, new Rectangle(15,15,35,35));
addChild(image);
Starling.current.nativeStage.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void
{
  image.width = e.stageX;
  image.height = e.stageY;
});

Avoid scaling if smaller than texture size :

var text:Texture = Texture.fromBitmap(new bitmap());

image = new Scale9Image(text, new Rectangle(15,15,35,35));
image.scaleIfSmaller = false;
addChild(image);
Starling.current.nativeStage.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void
{
  image.width = e.stageX;
  image.height = e.stageY;
});

Scale image :

you can scale your image if you want to

var text:Texture = Texture.fromBitmap(new bitmap());

image = new Scale9Image(text, new Rectangle(15,15,35,35));
image.scaleX = image.scaleY = 2;
addChild(image);
Starling.current.nativeStage.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void
{
  image.width = e.stageX;
  image.height = e.stageY;
});