1.BitmapText手动创建
let fnt = "ernn_cdifenzitiao".concat(ui.fnt);
let label:ui.BitmapText = new ui.BitmapText();
label.font = RES.getRes(fnt);
label.text = "200.00";
label.textAlign = egret.HorizontalAlign.CENTER;
label.x = 200;
label.y = 200;
this.addChild(label);
其中ernn_cdifenzitiao 是合成的字体,这样就能手动创建一个BitmapText了。
下面是整理的一些手动控件工具类:
/**
* 根据name关键字创建一个Button对象。name属性请参考resources/resource.json配置文件的内容。
*/
public static createButton():ui.Button{
let button = new ui.Button();
button.label = "";
return button;
}
/**
* 根据name关键字创建一个Button对象。name属性请参考resources/resource.json配置文件的内容。
*/
public static createImage(name:string):ui.Image{
name = name.concat(ui.png);
let texture:egret.Texture = RES.getRes(name);
let image:ui.Image = new ui.Image(texture);
return image;
}
/**
* 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
* Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
*/
public static createBitmap(name: string): ui.Bitmap {
let result = new ui.Bitmap(name);
// result.loadTexture(name)
return result;
}
/**
* 创建label
*/
public static createLabel(text:string="test",size:number=26,color:number=display.colorWhite):ui.Label
{
let label:ui.Label = new ui.Label();
label.text = text;
label.size = size;
label.textColor = color;
label.textAlign = egret.HorizontalAlign.CENTER;
return label;
}
/**
* 创建BitmapText
*/
public static createBitmapText(text:string="test",fnt:string=""):ui.BitmapText
{
fnt = fnt.concat(ui.fnt);
let texture:egret.Texture = RES.getRes(name);
let label:ui.BitmapText = new ui.BitmapText();
label.font = RES.getRes(fnt);
label.text = text;
label.textAlign = egret.HorizontalAlign.CENTER;
return label;
}
/**
* 九宫格根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
* Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
*/
public static create9Bitmap(name: string,rect:egret.Rectangle=new egret.Rectangle(0,0,100,100)): ui.Bitmap {
name = name.concat(ui.png);
let result = new ui.Bitmap(name);
// let texture: egret.Texture = RES.getRes(name);
// result.texture = texture;
result.setScale9Enabled(true);
result.setScale9Grid(rect);
return result;
}
public static createAnimate(effectFile,frameRate):ui.MovieClip {
let json = RES.getRes(effectFile + "_json");
let texture = RES.getRes(effectFile + "_png");
if (!json || !texture) {
Log.log("[Animation] 文件不存在/文件未加载: " + effectFile);
return null;
} else {
let effectMcFactory:egret.MovieClipDataFactory = new egret.MovieClipDataFactory(json, texture);
let effectMc:ui.MovieClip = new ui.MovieClip(effectMcFactory.generateMovieClipData(effectFile));
effectMc.frameRate = frameRate;
return effectMc;
}
}
public static createParticle(file) {
let texture = RES.getRes(file.toString() + "_png");
let config = RES.getRes(file.toString() + "_json");
if (texture && config) {
// var p:particle.GravityParticleSystem = new particle.GravityParticleSystem(texture, config);
// p.start();
// return p;
} else {
return null;
}
}
public static createGroup()
{
return new ui.Group();
}
public static createComponent()
{
return new ui.Component();
}
if(flag)
{
}
else
{
source = source.concat(ui.png);
return RES.getRes(source);
}
let t:egret.Texture = new egret.Texture()
t.bitmapData = new egret.BitmapData(source)
return t//RES.getRes(source);
}
/**
* 设置图片
*/
public static loadTexture(node:egret.Bitmap,source?: string | egret.Texture):void
{
if(CommonData.isEmpty(source))
{
return;
}
if(node)
{
let texture:egret.Texture;
if(typeof(source) == "string")
{
texture = RES.getRes(source.concat(ui.png));
}
else
{
texture = source;
}
node.texture = texture;
display.setAnchorPoint(node);
}
}
/**
* btn 按钮
* normal 正常状态
* selected 选中状态
* disabled 禁用状态
* 图片路径默认 a_png a-on_png a-dis_png
*/
public static loadTextures(btn:eui.Button, normal:string, selected:string="", disabled:string=""):void
{
if(btn)
{
if(!CommonData.isEmpty(normal))
{
let $img2Btn_normal : eui.Image = <eui.Image>btn.getChildAt(0);
$img2Btn_normal.source = RES.getRes(normal.concat(ui.png));
// Log.log("normal = "+normal);
}
else
{
return;
}
if( btn.skin != null && btn.skin.states != null){
let arr2States : eui.State[] = btn.skin.states;
let target2State : eui.State = null;
//up - 状态
target2State = arr2States[1];
let property2up: eui.SetProperty = <eui.SetProperty>target2State.overrides[ target2State.overrides.length -1];
if(CommonData.isEmpty(selected))
{
selected = normal;
}
selected = selected.concat("-on"+ui.png);
if( property2up.name == "source"){
// Log.log("selected 3 = "+selected);
property2up.value = RES.getRes(selected);
}
}
display.setAnchorPoint(btn);
}
}
/**
* 延时函数
*/
public static performWithDelay(func:Function=null,delay:number=0,thisObject:any=null,isAutoSave:boolean=true,...args: any[]):number
{
if(func==null)
{
return;
}
if(!thisObject)
{
thisObject = GlobalVar.Director.getMainScene();
func.bind(thisObject);
}
delay = delay * 1000;
let id = egret.setTimeout(<any>func,thisObject,delay,...args);
if(isAutoSave && (thisObject instanceof ui.Layer || thisObject instanceof Hall.BaseSkinLayer))
{
let action = new ui.Action(id);
thisObject.pushPerformAction(action);
}
return id;
}
/**
* 停止延时动作
*/
public static stopAction(id:number):void
{
egret.clearTimeout(id);
}
/**
* RepeatForever
*/
public static schedule(func:Function=null,delay:number=0,thisObject:any=null,isAutoSave:boolean=true,...args: any[]):number
{
if(func==null)
{
return;
}
if(!thisObject)
{
thisObject = GlobalVar.Director.getMainScene();
func.bind(thisObject);
}
delay = delay * 1000;
let id = egret.setInterval(<any>func,thisObject,delay,...args);
if(isAutoSave && (thisObject instanceof ui.Layer || thisObject instanceof Hall.BaseSkinLayer))
{
let action = new ui.Action(id);
thisObject.pushScheduleAction(action);
}
return id;
}
/**
* 停止重复动作
*/
public static stopRepeatAction(id:number):void
{
egret.clearInterval(id);
}