egret贝塞尔曲线运动
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贝塞尔曲线运动的更多相关文章
- Unity3d 简单的小球沿贝塞尔曲线运动(适合场景漫游使用)
简单的小球沿贝塞尔曲线运动,适合场景漫游使用 贝塞尔曲线:(贝塞尔曲线的基本想法部分摘自http://blog.csdn.net/u010019717/article/details/4768 ...
- html5 canvas高级贝塞尔曲线运动动画(好吧这一篇被批的体无完肤!都说看不懂了!没办法加注释了!当然数学不好的我也没办法了,当然这还涉及到一门叫做计算机图形学的学科)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【转】Itween 贝塞尔曲线(一)
原地址:点击打开链接 1.回调函数 回调函数,即当动画完成时那瞬间需要执行一次的一个函数,it中默认有一个onComplete函数,当动画完成时会自动执行,且你可以提供需要传递的一些参数.见如下代码: ...
- cocos2dx 3.x(常见的46种动作)
Sprite * sp= Sprite::create("Icon.png"); sp->setPosition(Vec2(, )); addChild(sp,,); // ...
- cocos2dx常见的46中+22中动作详解
cocos2dx常见的46中+22中动作详解 分类: iOS2013-10-16 00:44 1429人阅读 评论(0) 收藏 举报 bool HelloWorld::init(){ ///// ...
- [Cocos2d-x For WP8]Action 常用动作
Action相当于是Cocos2d-x里面的动画操作,在Cocos2d-x里面的动画基类是CCAction类,从CCAction类派生出来的就有很多常用的动作的实现类,利用这些类就可以给我们游戏的精灵 ...
- 转载cocos2dx的各种动作用法
以下内容来源于:http://www.cnblogs.com/linux-ios/archive/2013/04/06/3001946.html 转载时请保留以上链接. bool HelloWorld ...
- Cocos2d-x 3.0 动作
http://blog.csdn.net/lnb333666/article/details/16858635 //运行一个action动作对象 runAction("action对象&qu ...
- cocos2d-x 3.1.1 学习笔记[3]Action 动作
这些动画貌似都非常多的样子,就所有都创建一次. 代码例如以下: /* 动画*/ auto sp = Sprite::create("card_bg_big_26.jpg"); Si ...
随机推荐
- mybatis之Mybatis_demo
这篇博文通过简单的CRUD案例,让大家能够快速的上手,使用mybatis. 1,在eclipse中新建java project项目 mybatis_demo 2,在mybatis_demo项目中建 ...
- 20165306 Exp1 PC平台逆向破解
20165306 Exp1 PC平台逆向破解 一.逆向及Bof基础实践说明 1. 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,fo ...
- 【python 3】 文件操作
文件操作 一: 只读.读写 # 示例: 1 f = open("E:\人员名单.txt" , encoding="utf-8" , mode="r&q ...
- Win10升级惹的祸,Oracle服务全没有了,怎么解决?
最近Win10自动升级,升级后各种服务全部没了,心已经凉了一半... 百度\Google了一大堆,无非就几种:卸载重装,还原到上一版Win10,甚至重装系统,对于正式使用的库来说,够崩溃的了.. 搜寻 ...
- Qt中隐藏滚动条重新实现鼠标滚轮事件wheelEvent
delta()已经被弃用了,QT5中用的是angleDelta(),计算的时候取angleDelta().y()值. #重载方法wheelEvent(self,event),即滚轮事件方法 #---- ...
- python 装饰器问题及解决方式
#统计函数运行时间 import time #装饰器 def timmer(func): def wrapper(*args,**kwargs): start_time=time.time() fun ...
- Failed to find configured root that contains
这个主要问题是在android系统下7.0 拍照时,Android提供FileProvider类来供应用之间共享数据. 出现这个问题多为xml文件 path 类型和代码中调用的类型不同导致的 以下为多 ...
- SQLyog 连接主机的时候出现错误
这个 连接主机的时候出现: 这个时候打开cmd 找到mysql 的bin目录 输入 mysqld -nt -remove 即可 直接登录,注意这里的d代表的是服务端 接下来就可以不用输入密码直 ...
- Response.End ,Response.Redirect、Server.Transfer 引发 “正在中止线程”异常的问题
google后得知:Response.End 方法终止页的执行,并将此执行切换到应用程序的事件管线中的 Application_EndRequest 事件,同时抛出ThreadAbortExcepti ...
- SQL server 2012安装中出现的INSTALLSHAREDDIR 和 INSTALLSHAREDWOWDIR 参数具有相同的值问题
出现的问题如下: INSTALLSHAREDDIR 和 INSTALLSHAREDWOWDIR 参数具有相同的值“D:\soft\sql”.但是,这些参数必须具有不同的值.请为其中一个参数指定不同的值 ...