Zuflus Posted March 9, 2017 Share Posted March 9, 2017 Hello, I have trouble finding out how to make the start menu work together with the game. in the create() function I have this: function create() { var bg = game.add.sprite(game.world.centerX, game.world.centerY, "startBg"); var image = game.add.sprite(600, 300, "startButton"); bg.anchor.set(0.5); image.anchor.set(0.5); image.inputEnabled = true text = game.add.text(250, 16, "", {fill: "#ffffff"}); image.events.onInputDown.add(listener, this); game.world.setBounds(0, 0, 1400, 600); game.stage.backgroundColor = '#182d3b'; game.physics.startSystem(Phaser.Physics.ARCADE); //game.add.sprite(0,0) //Background platforms = game.add.group(); platforms.enableBody = true; var ground = platforms.create(0,game.world.height-64,"ground"); ground.scale.setTo(1,1); ground.body.immovable = true; var ledge = platforms.create(300, 80, "ground"); ledge.body.immovable = true; var ledge2 = platforms.create(-100, 250, "ground"); ledge2.body.immovable = true; player = game.add.sprite(64, 64, "character"); ai = game.add.image(100,100, "ghost"); player.anchor.setTo(0.5, 0.5); game.camera.follow(player); game.physics.arcade.enable(player); player.body.gravity.y = 400; player.body.collideWorldBounds = true; //player.body.bounce.y = 0.2; player.animations.add("right",[11,12,13,14,15,16,17,18,20], 20, true); player.animations.add("left",[0,1,2,3,4,5,6,7,8,9], 20, true); cursors = game.input.keyboard.createCursorKeys(); } I made a large gap so it's easier to see what's the start menu and what's the game, start menu is on top. The thing is I need this image.events.onInputDown.add(listener, this); to make what's on the bottom. I made a function named listener that created the game when i clicked on the button. That worked, but only issue then was that the Update function that makes me able to move the character stopped working. as the update won't run over and over when I don't have the game code in the create function, it just run once and stops. How do I get these two to be more cooperative with each other ? so far I've only been able to either have one or the other. Link to comment Share on other sites More sharing options...
Zuflus Posted March 15, 2017 Author Share Posted March 15, 2017 Don't need help with this anymore, but if anyone sees this and wonder about the same. I got this to work by using something called states, followed this example: https://phaser.io/news/2015/06/using-states-tutorial Link to comment Share on other sites More sharing options...
Recommended Posts