<! DOCTYPE html> <meta charset= "Utf-8" > <script src= "Js/phaser.min.js" ></script> <body> <div id= "Phaser-example" ></div> <script> Create a game interface var game = new Phaser.game (A, Phaser.auto, ' phaser-example ', { }); var phasergame = function () { This.bmd = null; This.points = { ' X ': [32, 128, 256, 384, 512, 608], ' Y ': [240, 240, 240, 240, 240, 240] }; This.preload = function () {///when preload data is complete, execute create functions Game.load.image (' opensource ', ' images/opensource.jpg '); } }; Phasergame.prototype = { Create:function () { This.stage.backgroundColor = ' #204090 '; This.bmd = This.add.bitmapData (This.game.width, this.game.height); This.bmd.addToWorld (); var py = This.points.y; for (var i = 0; i < py.length; i++) { Py[i] = This.rnd.between (32, 432); } opensource = game.add.sprite (0, 0, ' opensource '); Tween = Game.add.tween (opensource). to ( {}, Phaser.Easing.Quartic.In, False, 0, 0) This.plot (); }, Plot:function () { This.bmd.clear (); var x = 1/game.width; for (var i = 0; I <= 1; i = = x) { var px = this.math.linearInterpolation (this.points.x, i); var py = this.math.linearInterpolation (this.points.y, i); var px = this.math.bezierInterpolation (this.points.x, i); var py = this.math.bezierInterpolation (this.points.y, i); var px = this.math.catmullRomInterpolation (this.points.x, i); var py = this.math.catmullRomInterpolation (this.points.y, i); This.bmd.rect (px, py, 1, 1, ' Rgba (255, 255, 255, 1) '); Console.log (px%2); if (Px%8 > 6) { Tween.to ( {x:px,y:py}, Phaser.Easing.Linear.In, False, 0, 0); } } Tween.start (); /* Debug * * for (var p = 0; p < this.points.x.length; p++) { This.bmd.rect (This.points.x[p]-3, this.points.y[p]-3, 6, 6, ' Rgba (255, 0, 0, 1) '); } } }; Game.state.add (' Game ', Phasergame, true); </script> </body>
|