Jump to content

Get a button to start the game


Zuflus
 Share

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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