Moving with Gravity

Hello! I need help figuring out how to get my sprite to move left and right as it falls because of the built-in gravity. I don’t know why but whenever I try to use the cursor function to move left and right I can’t get any input to the sprite.

<script type="text/javascript">
var config = {
    type: Phaser.WEBGL,
    width: 1300,
    height: 600,
    backgroundColor: '#000',
    //parent: 'phaser-example',
    physics: {
        default: 'arcade',
            arcade: {
            gravity: { y: 300 },
            debug: true
    scene: {
        preload: preload,
        create: create

var game = new Phaser.Game(config);

function preload ()
    this.load.image('bg', 'assets/background.png');
    this.load.image('star', 'assets/sprites/peonay.png');

function create ()
    //camera and world bounds
    this.cameras.main.setBounds(0, 0, 1000  , 1200 );, 0, 850 , 1200);

    //adding the background
    this.add.image(250, 0, 'bg').setOrigin(0);

    player = this.physics.add.sprite(650, 0, 'star');


    this.cameras.main.startFollow(player, true, 0.05, 0.05);

    cursors = this.input.keyboard.createCursorKeys();

function update () {
    if (cursors.left.isDown)
    else if (cursors.right.isDown)




You can check in the update function if the actual player.x is bigger than the last frame or lower and play the respective animation

I’m not quite sure what you mean. The star at the moment doesn’t move at all. I’m just trying to get the star to fall while also being able to move it left and right.

If this is the whole code, then only the create function knows there is player. You have to make the player var global or part of scene class (using this).

From memory I think the value of gravity is much lower, more around 1 and not 300.

Your update() function isn’t getting run. It needs to be added to the scene config.

scene: {
  preload: preload,
  create: create,
  update: update