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 ...
随机推荐
- 【做题】UOJ450 - 复读机——单位根反演
原文链接 https://www.cnblogs.com/cly-none/p/UOJ450.html 题意:请自行阅读. 考虑用生成函数来表示答案.因为秒之间是有序的,所以这应当是个指数生成函数.故 ...
- Cent OS & Windows 双系统自定义引导菜单
系统环境 系统:Windows 10 (64-bit) & Cent OS 7 (64-bit) 引导程序:Grub2 编辑 grub.cfg 为了方便,在终端使用命令 su 输入密码进入超级 ...
- 前端基础面试题(JS部分)
1.几种基本数据类型?复杂数据类型?值类型和引用数据类型?堆栈数据结构? 基本数据类型:Undefined.Null.Boolean.Number.String 值类型:数值.布尔值.null.und ...
- 拿取页面值 跟拿取value里面的值
拿取页面输入框的数值 使用 val() val()设置或返回表单字段的值 拿取value里面的数值 value(); attr() 获取属性值
- Unity外包 UE4外包 项目案例平台开通通知
长年承接Unity外包 UE4外包,大家好,本公司团队已将案例上传至专门的案例官网. 欢迎联系我们索取,谢谢! 有项目外包请联系QQ:372900288 索取案例.
- 将python中的一个float变量转成内存的4个字节值
#coding=utf- from struct import pack,unpack byte=pack('f',1.5) print(byte) print([i for i in byte]) ...
- Bate冲刺 第四天
1.各个成员今日完成的任务及对项目的贡献小时数 姓名 今日已完成任务 时间 马玉婷 特殊字符测试与完善 5h 马美玲 菜单栏测试与完善 5h 益西卓嘎 撰写博文 1h 2. 提供当天站立式会议照片一张 ...
- springboot后台控制重定向
第一种方式: 1. 使用 @Controller 注解而不是 @RestController 2.方法上不要加 @ResponseBody 然后直接返回你要去的页面 比如 return & ...
- regression | p-value | Simple (bivariate) linear model | 线性回归 | 多重检验 | FDR | BH | R代码
P122, 这是IQR method课的第一次作业,需要统计检验,x和y是否显著的有线性关系. Assignment 1 1) Find a small bivariate dataset (pref ...
- 安装和启动json-server
安装json-server JSON-Server 是一个 Node 模块,运行 Express 服务器,你可以指定一个 json 文件作为 api 的数据源 npm i -g json-server ...