JSFiddle - React, Tailwind, and code Playground
by shiqangpan
HTML
<script src="https://github.com/photonstorm/phaser/releases/download/v3.2.0/phaser.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
JavaScript
var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
scene: {
preload: preload,
create: create,
update: update
},
width: 800,
height: 600
};
var game = new Phaser.Game(config);
var player;
function preload()
{
this.load.baseURL = '//examples.phaser.io/';
this.load.crossOrigin = 'anonymous';
this.load.image('dude', 'assets/sprites/phaser-dude.png');
}
function create()
{
player= this.add.sprite(256,50,'dude');
tweendata = {
targets: player,
x: 512,
duration: 1000,
yoyo:true,
ease: "Cubic.easeIn"}
tw = this.tweens.add(tweendata);
c = 0;
}
function update()
{
c++;
if(c>60){
c = 0;
var p= this.add.sprite(256,Math.random()*500+50,'dude');
tw.data[0].target = p;
tw.restart();
}
}