Sign in to follow this  
tanskuu

My menu doesnt work

Recommended Posts

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    physics: {
        default: 'arcade',
        arcade: {
            gravity: { y: 0 }
        }

    },

    scene: {
        preload: preload,
        create: create,
        update: update,
        scene: [Scene1]

    },



};



var game = new Phaser.Game(config);
var canFire = true;
var weaponTimer;
var fireRate;



function preload() {
    this.load.image('player', 'assets/player.jpg');
    this.load.image('green', 'assets/VihuColor.png');
    this.load.image('purple', 'assets/purplegoo.jpg');
    this.load.image('projectile', 'assets/projectile.png')

}

function create() {

    //luodaan pelaaja
    player = this.physics.add.image(400, 500, 'player');
    player.setCollideWorldBounds(true);
    player.body.setGravityY(0);

    //painovoima pelimaailmaan


    //luodaan vihut

    enemies = this.physics.add.group({
        key: 'green',
        repeat: 10,
        velocityY: 15,
        collideWorldBounds: true,
        setXY: { x: 50, y: 50, stepX: 100 },


    });
    enemies2 = this.physics.add.group({
        key: 'purple',
        repeat: 20,
        velocityY: 15,
        collideWorldBounds: true,
        setXY: { x: 25, y: 100, stepX: 50 }

    });



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

}

function update() {

    var time = Date.now();
    if (cursors.left.isDown) {
        player.setVelocityX(-300);
    } else if (cursors.right.isDown) {
        player.setVelocityX(300);
    } else if (canFire && cursors.up.isDown) {

        projectile = this.physics.add.group({
            key: 'projectile',
            repeat: 0,
            velocityY: -100,
            setXY: { x: player.x, y: player.y - 20 }
        });
        this.physics.add.collider(projectile, enemies);
        this.physics.add.collider(projectile, enemies2);
        canFire = false;
        weaponTimer = this.time.delayedCall(500, enableFire, [], this);
    } else {
        player.setVelocityX(0);
    }
}

function enableFire() {
    canFire = true;
}
--------

class Scene1 extends Phaser.Scene {
    constructor() {
        super({key:"Scene1"});
    }

    preload() {
        
        this.load.image('menu', 'assets/menu.png');
    }
    
    create() {
        this.image = this.add.image(400, 300, 'menu');
        this.input.once('pointerdown', function () {

            this.scene.start('game');

        }, this);
    }
}

Hi

pretty new to phaser and also to javascript. Cant seem to get my menu scene to work. It only shows the game not the menu before it.

Share this post


Link to post
Share on other sites
  scene: {
        preload: preload,
        create: create,
        update: update,
        scene: [Scene1]

    },

 

it seems that the preload, create, and update, will run first before Scene1's preload, create, and update. If you want to change the order, you create a game scene class, just like you did with scene1(recommended approach) or you can put all your gameplay code in Scene1 and all the menu code in preload, create, and update.

 

it seems you dont even have a game scene. (thanks for linking my tutorial, hopefully it helps)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.