# How can I create an infinite loop similar to setTimeOut?

**URL:** <https://phaser.discourse.group/t/how-can-i-create-an-infinite-loop-similar-to-settimeout/10173>\
**Category:** Phaser 3\
**Created:** [August 27, 2021, 12:24am UTC](https://phaser.discourse.group/t/how-can-i-create-an-infinite-loop-similar-to-settimeout/10173 "2021-08-27T00:24:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ederish\_Herrera](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/ederish_herrera/32/5534_2.png) [@Ederish\_Herrera](https://phaser.discourse.group/u/Ederish_Herrera)\
**Post date:** [August 27, 2021, 12:24am UTC](https://phaser.discourse.group/t/how-can-i-create-an-infinite-loop-similar-to-settimeout/10173/1 "2021-08-27T00:24:08Z")

</div>

hi i’m new to phaser 3 and i have a lot of problems.  
as I can create an infinite platforms loop like in this example: [Phaser - Examples - Time - Basic Repeat Event](https://phaser.io/examples/v2/time/basic-repeat-event) try with:

```javascript
 game.time.events.repeat(Phaser.Timer.SECOND * 2, 10, createBall, this);
function createPlataformsl() {
plataforms = this.physics.add.sprite(Phaser.Math.Between(0,600), 0, 'barra').setDisplaySize(200, 200).setSize(80,8);
}

```

for some reason it doesn’t work  
game demo:  
[https://games.phasereditor2d.com/Ederishh/Game/](https://games.phasereditor2d.com/Ederishh/Game/)

```javascript
type or paste code here
var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    parent: 'container',
    physics: {
        default: 'arcade',
        arcade: { gravity: { y:70 },
        debug: false
        }
    },
    scene: {
        preload: preload,
        create: create,
        update: update
    }
  };
  var game = new Phaser.Game(config);
  var cursors;
  var player;
  var score = 0;
  var scoreText;
  var plataforms;
  function preload (){
  //----------------------pleyer-------------------//
  this.load.image('ball', 'assets/Ball.png');
  //----------------------Background-------------------//
  this.load.image('background', 'assets/lofi-1.jpg');
  //----------------------Audio-------------------//
  this.load.audio('leve-1','assets/level-1.mp3');
  //----------------------plataforms-------------------//
  this.load.image('barra','assets/barra.png');
  }
  function create (){
  //-----------------backgraund-------------//
  this.add.image(400, 300, 'background').setDisplaySize(800, 600);
  //--------------------Audio-------------------------------------//
  let audio = this.sound.add('leve-1',{loop:true}); audio.play();
  //-------------------- Puntuacion -------------------------------------//
  scoreText = this.add.text(16, 16, 'score: 0', { fontSize: '32px', fill: '#fff' });
  //-------------------- fisicas de la bola -------------------------------------//
  player = this.physics.add.sprite(Phaser.Math.Between(0,600), 0, 'ball');
  player.setDisplaySize(50,50);
  player.setGravityY(20000);
  player.setCollideWorldBounds(true);
  player.setBounce(0.70);
  //------------------ plataformas --------------//
  //game.time.events.repeat(Phaser.Timer.SECOND * 2, 10, createPlataforms, this);//
  //function createPlataforms(){
    this.barra = this.physics.add.sprite(Phaser.Math.Between(0,600), 0, 'barra');
    this.barra.setDisplaySize(200, 200)
    this.barra.setSize(80,8)
    //} 
  //-------------------crear controles----------//
  cursors = this.input.keyboard.createCursorKeys();
  //----------------------- Colisiones -----------//
  this.physics.add.collider(player,this.barra);
  
  this.barra.body.checkCollision.up = true;
  this.barra.body.checkCollision.down = false;
  this.barra.body.checkCollision.left = false;
  this.barra.body.checkCollision.right = false;
  }
  function update (){ 
  //-----------------controles----------------//
  player.setVelocity(0);
  if (cursors.left.isDown){
  player.setVelocityX(-500);
  }
  else if (cursors.right.isDown){
  player.setVelocityX(500); 
  }
  if (cursors.space.isDown){
  player.setVelocityY(-500);
  }}

```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 27, 2021, 12:25am UTC](https://phaser.discourse.group/t/how-can-i-create-an-infinite-loop-similar-to-settimeout/10173/2 "2021-08-27T00:25:25Z")

</div>

You need to follow the v3 examples: [Phaser - Examples - Time](https://phaser.io/examples/v3/category/time)
