tanskuu Posted November 13, 2018 Share Posted November 13, 2018 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. Link to comment Share on other sites More sharing options...
SovietSenpai23 Posted November 14, 2018 Share Posted November 14, 2018 I'm newbie too but maybe you should call this in the (main) create() function: this.scene.start('Scene1'); Also this video might help: Link to comment Share on other sites More sharing options...
jest Posted November 15, 2018 Share Posted November 15, 2018 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) Link to comment Share on other sites More sharing options...
tanskuu Posted November 15, 2018 Author Share Posted November 15, 2018 Thanks for the tips. It seems to work now! ? Link to comment Share on other sites More sharing options...
Recommended Posts