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. Git学习笔记——分支

    分支用法很多,比如bug修复,协作管理,这里只简单介绍我在工作中用到的协作模式. 场景:我自己开发独立功能,在本地为自己创建一个分支就叫localbranch吧,甭管master到哪了,我只管开发我的 ...

  2. EvansClassification

    EvansClassification In his excellent book Domain Driven Design, Eric Evans creates a classification ...

  3. java 随机出题四则运算

    作业要求来源于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2186 我的github地址:https://github.com/k ...

  4. 后台启动mysql

    https://blog.csdn.net/codemacket/article/details/77719323

  5. HDU 5616 Jam's balance(Jam的天平)

    HDU 5616 Jam's balance(Jam的天平) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ...

  6. hp quicktestprofession ver-10.0(QTP)的入门使用指南

    ---恢复内容开始--- SQA(software quality assurance) tool hp quicktestprofession ver-10.0(QTP) environment w ...

  7. Lintcode489-Convert Array List to Linked List-Easy

    489. Convert Array List to Linked List Convert an array list to a linked list. Example Example 1: In ...

  8. 7_linux用户及权限(2)和管理

    useradd:useradd [options] USERNAME -u UID -g GID(基本组) -G GID,...(附加组) //省略号表示可以有多个,彼此之间用逗号隔开 -c &quo ...

  9. h5视频播放

    h5视频播放 一直在写js原生的东西,感觉总是停滞不前,现在我们应该学一些h5新的特性,因为我们毕竟是从事前端的,下面我们一起来写一个视频播放吧 1,html <div class=" ...

  10. SQL Server 2008 无法安装U890

    安装U890,环境检测的时候,却提示数据库不符合要求, 解决方法: 通过修改SQLServer的版本号 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServ ...