Jump to content

Button Bug!


TrinityCore
 Share

Recommended Posts

Hello Guys

 

I have a problem with the buttons on phaser

They do not change the texture as indicated in the code

Game: 

var PhaserGame = new Phaser.Game(1200, 640, Phaser.AUTO, "PhaserGame");
var Preload;
var MainMenu;
PhaserGame.state.add("Preload", Preload);
PhaserGame.state.add("MainMenu", MainMenu);
PhaserGame.state.start("Preload");

Preload:

Preload = {

	preload: function(){

	},

	create: function(){

		PhaserGame.load.onLoadComplete.add(Finished, this);
		Preloaders();

	},


	update: function(){},

}

function Preloaders(){
	PhaserGame.load.image("Background", "./images/Assest/Background001.png");
	PhaserGame.load.spritesheet("Button", "./images/Buttons/Button.png", 108, 48);
	PhaserGame.load.start();
}

function Finished(){
	PhaserGame.state.start("MainMenu");
}

MainMenu:

MainMenu = {

	preload: function(){
		
	},

	create: function(){

		Background = PhaserGame.add.tileSprite(0, 0, 1200, 640, "Background");
		Button = PhaserGame.add.button(10, 10, "Button", Tester, this, 0, 1);

	},

	update: function(){

	},

}

function Tester(object){
	console.log("Clicked");
}

The button does not change texture, and the mouse cursor changes state: Normal to Pointer, but steadily at the slightest movement on the button (without even getting out of it).

What could be the reason for this error?

Button:

Botton.png

I have tried with the following things:

1- Download the library again (Version 2.7.7).

2- Restart my computer.

3- Delete history, cookies, and everything that can be removed (Completely everything!).

4- Create all states from scratch.

What I can be doing wrong?

 

I hope you can help me.

Link to comment
Share on other sites

3 hours ago, ncil said:

Hello! I think the problem is with your actual button image file. The frames should go from left to right, not top to bottom. So your image should be 216x48 pixels. Try that.

No, the image is fine, the problem was that it was loading two identical files, one in the preload state and another in the state of MainMenu, which caused a kind of strange update.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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