一个旋转的小球
class Ball extends Laya.Sprite{ private static cached:boolean = false; private body:Laya.Sprite; constructor(){ super(); this.init(); } public init():void{ if(!Ball.cached){ Ball.cached = true; this.body = new Laya.Sprite(); this.body.loadImage("war/ball.png"); this.body.pivot(12,12); } this.addChild(this.body); Laya.timer.frameLoop(1,this,this.animate); } private animate(e):void{ this.body.rotation += 10; }}
通过贝塞尔曲线 获得一个投石车一样的效果
class Main{ private ball:Ball; private targetX:number = 600; private targetY:number = 300; private centerX:number = 0; private centerY:number = 0; private angle:number = Math.PI; private angle2:number = 0; private radius:number = 150; //半径 private speed:number = .05; private points:Array= []; private i:number = 0; constructor() { Laya.init(1100, 619, Laya.WebGL); Laya.loader.load("res/atlas/war.atlas",Laya.Handler.create(this,this.onLoaded),null,Laya.Loader.ATLAS); } private onLoaded():void{ this.ball = new Ball(); Laya.stage.addChild(this.ball); this.ball.x = Laya.stage.width / 2; this.ball.y = Laya.stage.height / 2; Laya.stage.on(Laya.Event.CLICK,this,this.onClick); Laya.timer.frameLoop(1,this,this.onEnterFrame); } private onEnterFrame():void{ if(this.points.length>0){ if(this.i 0) { cs *= start; bcs *= end; start--; end--; } return (cs / bcs); }; for (var i = 0; i < len; i++) { var point = points[i]; x += point.x * Math.pow((1 - t), (len - 1 - i)) * Math.pow(t, i) * (erxiangshi(len - 1, i)); y += point.y * Math.pow((1 - t), (len - 1 - i)) * Math.pow(t, i) * (erxiangshi(len - 1, i)); } return { x: x, y: y };}new Main();