Adding obstacles - endless game

Hi there,

I am trying to make very simple game, but I am struggling with one key feature - adding unlimited obstacles that are coming closer to the player, who is trying to jump over them.

I´ve been looking for the solutions for days, but i found only instructions for Phaser 2. I am very new to Phaser/Javascript.

This is what my game look now:

My code:

Blockquote

var game;
var gameOptions = {



    obstacleSpeed: 250,

    obstacleDistanceRange: [200, 300],

    obstacleHeightRange: [20, 80],

    localStorageName: 'bestballscore',
}

var gameConfig = {
    type: Phaser.AUTO,
    backgroundColor:0x87ceeb,
    scale: {
        mode: Phaser.Scale.FIT,
        autoCenter: Phaser.Scale.CENTER_BOTH,
        width: 750,
        height: 500
    },
    physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 300 },
            debug: false
        }
    },
    scene: {
        preload: preload,
        create: create,
        update: update

    }
}
game = new Phaser.Game(gameConfig);

var ball;
var obstacles;
var ground;
var score = 0;
var obstacleX;

function preload(){
    this.load.image('sky', 'sky.png');
    this.load.image('ground', 'ground.png');
    this.load.image('ball', 'ball.png');
    this.load.spritesheet('obstacle', 'obstacle.png', {
        frameWidth: 20,
        frameHeight: 40
    })
}
function create() {

    this.add.image(400, 300, 'sky'); //prida pozadie

    ground = this.physics.add.staticGroup(); //nastavi ground ako fixny
    ground.create(game.config.width / 2, game.config.height / 4 * 3, 'ground').setScale(1.2).refreshBody();//vytvori ground


    ball = this.physics.add.sprite(100, 200, 'ball'); //vytvori loptu
    ball.setBounce(0.2); //odrazanie od ground

    this.physics.add.collider(ball, ground); //lopta sa zachyti o ground

function update(){
cursors = this.input.keyboard.createCursorKeys();

    if (cursors.up.isDown && ball.body.touching.down)
    {
        ball.setVelocityY(-280);
    }

}

Maybe have a look at