1、js代码运行顺序:
1)、先执行script中的所有同步代码,过程中把所有异步任务压进它们各自的队列(假设维护有process.nextTick队列、promise.then队列、setTimeout队列、setImmediate队列等4个队列)
2)、按照优先级(process.nextTick > promise.then > setTimeout > setImmediate),选定一个 不为空 的任务队列,按先进先出的顺序,依次执行所有任务,执行过程中新产生的异步任务继续压进各自的队列尾,直到被选定的任务队列清空。
3)、重复2...
2、在egret中制作帧动画让动画循环播放:
3、坐标转换 :获取组件全局坐标时,必须调用自己上层容器的localToGlobal方法
例子: this.group.localToGlobal(this.btn.x, this.btn.y);
4、使用粒子效果
//粒子效果
private system: particle.ParticleSystem;
if (!this.system) {
let texture = RES.getRes("wingold_png");
let config = RES.getRes("wingold_json");
this.system = new particle.GravityParticleSystem(texture, config);
this.system.emitterX = this.width / 2;
this.system.emitterY = this.height - 250;
this["groupParticle"].addChild(this.system);
this.system.start();
}
5、使用帧动画
//加载动画并播放
let data = RES.getRes("flowGold_json");
let txtr = RES.getRes("flowGold_png");
this.mcFactory = new egret.MovieClipDataFactory(data, txtr);
let money: egret.MovieClip = Pool.getItemBySign("money", egret.MovieClip, this.mcFactory.generateMovieClipData());
6、修改库文件后
运行:egret build -e
7、物理引擎p2的使用:
//创建world
var world: p2.World = new p2.World();
this.world = world;
world.sleepMode = p2.World.NO_SLEEPING;
// 设置弹力
world.defaultContactMaterial.restitution = 0;
// 创建地面刚体
var body: p2.Body = new p2.Body({
mass: 0,
position: [0, 0]
});
world.addBody(body);
// 添加圆形刚体
var boxShape: p2.Shape = new p2.Circle({ radius: radius });
var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY] });
boxBody.addShape(boxShape);
world.addBody(boxBody);
let img = self.createBitmapByName("ball_png"); // 创建一张图 用于展示
img .width = (
img .height = (
boxBody.displays = [img ]; //将这张图与刚体绑定
//注册侦听回调
egret.Ticker.getInstance().register(function (dt) {
if (dt < 10) {
return;
}
if (dt > 1000) {
return;
}
// world.step(dt / 1000);
//调整进行时间
world.step(1 / 60, dt / 1000, 10);
var stageHeight: number = egret.MainContext.instance.stage.stageHeight;
var l = world.bodies.length;
for (var i: number = 1; i < l; i++) {
var boxBody: p2.Body = world.bodies[i];
if (!boxBody.displays) continue;
var box: egret.DisplayObject = boxBody.displays[0];
if (box) {
box.x = boxBody.position[0] * factor;
box.y = stageHeight - boxBody.position[1] * factor;
box.rotation = 360 - (boxBody.angle + boxBody.shapes[0].angle) * 180 / Math.PI;
}
}
}, this);