buttons/button using texture atlas
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload() {
game.load.atlas('button', 'assets/buttons/button_texture_atlas.png', 'assets/buttons/button_texture_atlas.json');
game.load.image('background','assets/misc/starfield.jpg');
}
var button;
var background;
function create() {
game.stage.backgroundColor = '#182d3b';
background = game.add.tileSprite(0, 0, 800, 600, 'background');
button = game.add.button(game.world.centerX - 95, 400, 'button', actionOnClick, this, 'over', 'out', 'down');
button.onInputOver.add(over, this);
button.onInputOut.add(out, this);
}
function over() {
console.log('button over');
}
function out() {
console.log('button out');
}
function actionOnClick () {
background.visible =! background.visible;
}