Here is a game javascript code in the game.js file (You may add it into a Scene.js separate file for better organisation):
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
function preload(){
//loading all elements
this.load.image('coconut', 'assets/coconut.png');
}
function create(){
//group of objects added with physics
coconuts = this.physics.add.group({
key: 'coconut',
repeat: 4,
setXY: { x: 120, y: 60, stepX: 150, stepY: 40}
});
//In case we need to apply properties or modify individual objects from the added group
coconuts.children.iterate(function (child) {
child.setBounceY(Phaser.Math.FloatBetween(0.8, 1.0));
child.setCollideWorldBounds(true);
child.setVelocityX(Phaser.Math.FloatBetween(0.2, 1.0))
});
}