JSFiddle - React, Tailwind, and code Playground
by espace3d
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.1/phaser.min.js"></script>
JavaScript
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload,create: create, update: update, render: render });
var table
var sprite1
function preload() {
game.load.image('circle', 'https://s13.postimg.org/xjhlzmiev/disc_png.png');
game.load.image('rect', 'http://s10.postimg.org/6fa6mgrd5/motif.jpg');
}
var dim_sprite=100
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
sprite1=game.add.sprite(400, 300, 'rect');
sprite1.anchor.x=.5
sprite1.anchor.y=.5
sprite1.width=dim_sprite
sprite1.height=dim_sprite
sprite1.alpha=1
game.physics.enable(sprite1, Phaser.Physics.ARCADE);
table=[]
for (var j=0; j < 10 ;j++) {
table[j] = game.add.sprite(0, 0, 'rect')
table[j].width = 400
table[j].height = 1
table[j].x = 200
table[j].y = game.rnd.between(400,500)
table[j].alpha=1
game.physics.enable(table[j], Phaser.Physics.ARCADE);
table[j].body.immovable = true;
}
}
function update() {
sprite1.body.velocity.y = 100
for (var j=0; j < 10 ;j++) {
game.physics.arcade.collide(sprite1, table[j],collision,null,this);
}
}
function collision(obj1,obj2){
console.log("touch")
game.time.events.add(900,() => destroyTable(obj2),this)
}
function destroyTable(obj2){
obj2.body.enable=false
}
function render() {
}