Jump to content

Stuck With Controls


blackdragon321
 Share

Recommended Posts

Hello, I am trying to get my controls to work for my animations however I keep getting a "Uncaught TypeError: Cannot read property 'getFirstTick' of null" error. I will post my code. I am new to Phaser

 

import { CST } from "../CST";

var player, platforms, cursors;

export class GameScene extends Phaser.Scene{
    constructor(){
        super({
            key: CST.SCENES.GAME
        })
    }
create(){
    this.add.image(400, 300, "stage"); //Stage Background

    //Platforms
    platforms = this.physics.add.staticGroup(); //Creating Platform Object Static Group

    platforms.create(50, 460, "ground").setScale(.2).refreshBody();
    platforms.create(250, 460, "landing").setScale(.3).refreshBody();
    platforms.create(380, 410, "ramp").setScale(.3).refreshBody();
    platforms.create(550, 390, "ground").setScale(.2).refreshBody();

    //Player
    player = this.physics.add.sprite(50, 200, "brandon");

    player.setBounce(0.2);
    player.setCollideWorldBounds(true);

    this.anims.create({
        key: 'left',
        frames: this.anims.generateFrameNumbers("brandon", {start:0, end:3}),
        frameRate: 10,
        repeat: -1
    });
    this.anims.create({
        key: 'right',
        frames: this.anims.generateFrameNumbers("brandon", {start:0, end:-3}),
        frameRate: 10,
        repeat: -1
    });

    this.physics.add.collider(player, platforms); //Collision Checker
    cursors = this.input.keyboard.createCursorKeys();
    }
update(){
    if (cursors.left.isDown)
    {
        player.setVelocityX(-160);
        player.anims.play('left', true);
    }
    else if (cursors.right.isDown)
    {
        player.setVelocityX(160);
        player.anims.play('right', true);
    }
    else
    {
        player.setVelocityX(0);
        player.anims.play('turn');
    }

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

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...