class MtwGame {

public constructor() {
}
private static _instance: MtwGame;

public static get Instance(): MtwGame {
if (this._instance == null || this._instance == undefined) {
this._instance = new MtwGame();
}
return this._instance;
}

public stage: egret.Stage;
private ball:egret.Bitmap;
private isMoving:boolean = false;
p1:Array<number>;
p2:Array<number>;
//初始化舞台
public init(stage: egret.Stage): void {
this.stage = stage;

let sky:egret.Bitmap = this.createBitmapByName("bg_jpg");
this.stage.addChild(sky);
let stageW:number = this.stage.stageWidth;
let stageH:number = this.stage.stageHeight;
sky.width = stageW;
sky.height = stageH;

let roll:egret.Shape = new egret.Shape();
// roll.graphics.lineStyle(10, 0x00ff00 );
roll.graphics.beginFill( 0xff0000, 1);
roll.graphics.drawCircle( 0, 0, 3 );
roll.graphics.endFill();
this.stage.addChild( roll );

this.ball = this.createBitmapByName("egret_icon_png");
this.stage.addChild(this.ball);
this.ball.x = 100;
this.ball.y = 300;
this.p1 = [this.ball.x,this.ball.y];
this.ball.anchorOffsetX = this.ball.width>>1;
this.ball.anchorOffsetY = this.ball.height>>1;

this.stage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);

}

private onClick(e:egret.TouchEvent):void {

if (this.isMoving) {
return;
}
this.p2 = [Math.floor(e.stageX),Math.floor(e.stageY)];
this.isMoving = true;
egret.Tween.get(this).to({factor: 1}, 2000).call(this.moveOver, this);
}

public get factor():number {
return 0;
}

public set factor(value:number) {
//(100,300)锚点坐标
this.ball.x = (1 - value) * (1 - value) * this.p1[0] + 2 * value * (1 - value) * 100 + value * value * this.p2[0];
this.ball.y = (1 - value) * (1 - value) * this.p1[1] + 2 * value * (1 - value) * 300 + value * value * this.p2[1];
}

private moveOver():void {
this.isMoving = false;
this.p1 = this.p2;
}

/**
* 根据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.
*/
private createBitmapByName(name:string):egret.Bitmap {
var result = new egret.Bitmap();
var texture:egret.Texture = RES.getRes(name);
result.texture = texture;
return result;
}
}

//参考http://bbs.egret.com/forum.php?mod=viewthread&tid=1842&highlight=%E6%9B%B2%E7%BA%BF%E8%BF%90%E5%8A%A8

egret贝塞尔曲线运动的更多相关文章

  1. Unity3d 简单的小球沿贝塞尔曲线运动(适合场景漫游使用)

        简单的小球沿贝塞尔曲线运动,适合场景漫游使用 贝塞尔曲线:(贝塞尔曲线的基本想法部分摘自http://blog.csdn.net/u010019717/article/details/4768 ...

  2. html5 canvas高级贝塞尔曲线运动动画(好吧这一篇被批的体无完肤!都说看不懂了!没办法加注释了!当然数学不好的我也没办法了,当然这还涉及到一门叫做计算机图形学的学科)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 【转】Itween 贝塞尔曲线(一)

    原地址:点击打开链接 1.回调函数 回调函数,即当动画完成时那瞬间需要执行一次的一个函数,it中默认有一个onComplete函数,当动画完成时会自动执行,且你可以提供需要传递的一些参数.见如下代码: ...

  4. cocos2dx 3.x(常见的46种动作)

    Sprite * sp= Sprite::create("Icon.png"); sp->setPosition(Vec2(, )); addChild(sp,,); // ...

  5. cocos2dx常见的46中+22中动作详解

    cocos2dx常见的46中+22中动作详解 分类: iOS2013-10-16 00:44 1429人阅读 评论(0) 收藏 举报 bool HelloWorld::init(){    ///// ...

  6. [Cocos2d-x For WP8]Action 常用动作

    Action相当于是Cocos2d-x里面的动画操作,在Cocos2d-x里面的动画基类是CCAction类,从CCAction类派生出来的就有很多常用的动作的实现类,利用这些类就可以给我们游戏的精灵 ...

  7. 转载cocos2dx的各种动作用法

    以下内容来源于:http://www.cnblogs.com/linux-ios/archive/2013/04/06/3001946.html 转载时请保留以上链接. bool HelloWorld ...

  8. Cocos2d-x 3.0 动作

    http://blog.csdn.net/lnb333666/article/details/16858635 //运行一个action动作对象 runAction("action对象&qu ...

  9. cocos2d-x 3.1.1 学习笔记[3]Action 动作

    这些动画貌似都非常多的样子,就所有都创建一次. 代码例如以下: /* 动画*/ auto sp = Sprite::create("card_bg_big_26.jpg"); Si ...

随机推荐

  1. 【新特性】JDK10

    一.局部变量类型推断 很多人抱怨Java是一种强类型,需要引入大量的样板代码.甚至在这些情况下,给定好变量名,通常很清楚发生了什么,明显类型声明往往被认为是不必要的.许多流行的编程语言都已经支持某种形 ...

  2. 20175312 2018-2019-2 《Java程序设计》第6周学习总结

    20175312 2018-2019-2 <Java程序设计>第6周学习总结 教材学习内容总结 已依照蓝墨云班课的要求完成了第七.十章的学习,主要的学习渠道是PPT,和书的课后习题. 总结 ...

  3. android 百度地图 定位获取位置失败 62错误

    一切正常步骤进行但是还是没有获得定位,得到的坐标总是49E.xxxx,错误代码总是62 总是以为代码.或jar包.或还有什么权限没给.搞了好久,十分郁闷.在控制台上又没有什么具体的错误提示 经过无数次 ...

  4. java知识点集锦--基础知识部分

    1.面向对象特征:封装.继承.多态 封装:把数据和操作数据的方法绑定起来,对数据的访问只能通过已定义的接口来访问.面向对象的本质就是将现实世界描绘成一系列完全自治.封闭的对象.我们在类中编写的方法就是 ...

  5. zookeeper调试命令

    转载自 https://www.cnblogs.com/andy6/p/7674028.html 一.zkServer.sh 1.查看 zkServer.sh 帮助信息[root@bigdata05 ...

  6. jieba库及词频统计

    import jieba txt = open("C:\\Users\\Administrator\\Desktop\\流浪地球.txt", "r", enco ...

  7. Python自学:第三章 弹出列表中任何位置处的元素

    motorcycles = ["honda", "yamaha", "suzuki"] first_owned = motorcycles. ...

  8. Mtlab:抛物型方程的交替方向隐格式(ADI)

    tic; clear clc M=[,,,,]; N=M; :length(M) h=/M(p);% 这里定义空间步长等距 tau=/N(p); % 时间步长 x=:h:; y=:h:; t=:tau ...

  9. node.js 生成二维码

    因为自己的项目中,想在商品详情页上 显示一个 商品优惠券的二维码. 以此为需求. node.js 后台代码 const qr_image = require("qr-image") ...

  10. 'JetEntityFrameworkProvider' could not be loaded 解决办法

    原因:JetEntityFrameworkProvider引用的EntityFramework与你使用的版本不一致,造成程序加载这个DLL失败. 解决办法: 使用Reflect软件JetEntityF ...