I found the slow resion is:
package ru.stablex.ui.skins;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import ru.stablex.Assets;
import ru.stablex.ui.widgets.Widget;
/**
* 3-slice-scaling
*
*/
class Slice3 extends Skin {
//Asset ID or path to bitmap
public var src (get_src,set_src): String;
public var _src : String = null;
/**
This file has been truncated. show original
private function _skinDrawSlice(w:Widget, bmp:BitmapData, src:Rectangle, dst:Rectangle) : Void {
var mx : Matrix = new Matrix();
mx.translate(-src.x, -src.y);
mx.scale(dst.width / src.width, dst.height / src.height);
mx.translate(dst.x, dst.y);
w.graphics.beginBitmapFill(bmp, mx, false, this.smooth);
w.graphics.drawRect(dst.x, dst.y, dst.width, dst.height);
w.graphics.endFill();
}
w.graphics.beginBitmapFill(bmp, mx, false, this.smooth);
using mx is very very slow!
I modify to
package ru.stablex.ui.skins;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import ru.stablex.Assets;
import ru.stablex.ui.widgets.Widget;
/**
* Tiled 9-slice-scaling
* Same as 9-slice, but instead of the scaling the middle part, it is tiled.
*/
class TiledSlice9 extends Slice9{
// The skin tries to slice and tile the image, so that
// the scale factor of in both x and y direction is as close as
// possible to this scale.
This file has been truncated. show original
if (use_tile){
if (tileset == null){
tileset = new Tileset (bmp);
}
var t_tile_w = Math.round(w.w);
var t_tile_h = Math.round(w.h);
//haxe.Log.trace("@draw tile! w,h="+t_tile_w+","+t_tile_h);
if (tilemap != null){
if (t_tile_w != tile_w || t_tile_h != tile_h){
if(tilemap.parent!=null){
tilemap.parent.removeChild(tilemap);
}
tilemap = null;
}
}
if (tilemap == null){
tile_w = t_tile_w;
tile_h = t_tile_h;
tilemap = new Tilemap(tile_w, tile_h, tileset, this.smooth);
w.addChildAt(tilemap,0);//重要
}
while(tilemap.numTiles > 0){
tilemap.removeTileAt(0);
}
var d = @:privateAccess tileset.__data;
if (d.length > 0){
@:privateAccess tileset.__data=[];
}
}
var tile_i = -1;
for (y in 0...(vTileCount+2)) {
dst.x = 0;
for (x in 0...(hTileCount+2)) {
// Set the src rect
var hSizeIndex = if (x == 0) {0;} else {if (x == hTileCount +1) {2;} else {1;}};
var vSizeIndex = if (y == 0) {0;} else {if (y == vTileCount +1) {2;} else {1;}};
src.x = srcRect.x + sum(hSizes.slice(0,hSizeIndex));
src.y = srcRect.y + sum(vSizes.slice(0,vSizeIndex));
// Set the distination width, based on the source width
src.width = hSizes[hSizeIndex];
src.height = vSizes[vSizeIndex];
dst.width = src.width * scaleX;
dst.height = src.height * scaleY;
if (use_tile){
tileset.addRect (src);
tile_i++;
var tile = new openfl.display.Tile (tile_i, dst.x, dst.y, (dst.width + 2) / src.width, (dst.height + 2) / src.height);
tilemap.addTile (tile);
}else{
this._skinDrawSlice(w, bmp, src, dst);
}
// Update destination x position
dst.x += dst.width;
}
// Update destination y position
dst.y += dst.height;
}
and also midify the by the similar code.
package ru.stablex.ui.skins;
import flash.geom.Matrix;
import ru.stablex.Assets;
import ru.stablex.ui.widgets.Widget;
import flash.display.BitmapData;
/**
* Img skin always set widget size the same as `.src` bitmapdata size
*
*/
class Img extends Skin{
//Asset ID or path to bitmap
public var src (get_src,set_src): String;
public var _src : String = null;
/**
* Use this property instead of `.src`, if you need to directly assign BitmapData instance.
* `.bitmapData` will be set to null automatically, if you set `.src`.
* `.src` will be set to null automatically, if you set `.bitmapData`
This file has been truncated. show original
package ru.stablex.ui.widgets;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.geom.Point;
import ru.stablex.Err;
/**
* Simple Bitmap. Bitmap is drawn using .graphics.beginBitmapFill()
*/
class Bmp extends Widget{
//Asset ID or path to bitmap
public var src (get_src,set_src): String;
@:noCompletion public var _src : String = null;
//Should we use smoothing?
public var smooth : Bool = true;
/** Does image should be scaled to actual size of widget? */
This file has been truncated. show original
the FPS is up to 60~80!