yigitozdemir Posted October 8, 2014 Share Posted October 8, 2014 Hello, I just started to work with making a simple menu. I have a simple script but it doesnt work. The error is: Uncaught TypeError: Cannot read property 'hasLoaded' of undefined And here is code:var game = new Phaser.Game(500,500, Phaser.AUTO, 'gamediv');game.mainMenu = function(){};game.mainMenu.prototype = { button:null, preload : function() { game.load.spritesheet('new_game_button', 'asset/button/newgame.png'); }, create : function() { this.button = game.add.button(game,50,50, 'new_game_button', function(){ console.log("h"); }, null, 2, 1 ,0); }, update : function() { }, }game.state.add('MainMenu', game.mainMenu);game.state.start('MainMenu');what is wrong with this code? How can i solve this issue? Regards! Link to comment Share on other sites More sharing options...
yigitozdemir Posted October 8, 2014 Author Share Posted October 8, 2014 I a little bit debugged the script, error comes from pixi.js and an error about a thing thats name is baseTexture, in pixi documentation it says, every texture has a base texture, but it doesn't meant me anything. Can anyone knows the solution of this problem?e Link to comment Share on other sites More sharing options...
spencerTL Posted October 8, 2014 Share Posted October 8, 2014 I've never used a spritesheet for buttons but shouldn't the preload line define the dimensions and number of frames? eggame.load.spritesheet('new_game_button', 'asset/button/newgame.png', 64, 64, 3);//for a sprite sheet made of 3 64 x 64 frames.This example seems to cover much of what you want:http://examples.phaser.io/_site/view_full.html?d=buttons&f=changing+the+frames.js&t=changing%20the%20frames Link to comment Share on other sites More sharing options...
yigitozdemir Posted October 8, 2014 Author Share Posted October 8, 2014 With spencerTL's contrubution i solved error. I took a look to button examples and documentation of loader. I've tried to implement like here:http://docs.phaser.io/Phaser.Button.html but right implemetation of Game.add.button is like this: http://docs.phaser.io/Phaser.GameObjectFactory.html#button So i updated my source code to this:var game = new Phaser.Game(500,500, Phaser.AUTO, 'gamediv');var button;var mainMenu = { preload : function() { game.load.spritesheet('new_game_button', 'asset/button/newgame.png',128,50); }, create : function() { button = game.add.button(50,50, 'new_game_button', function(){ console.log("h"); }, null, 2, 1 ,0); }, update : function() { }, }game.state.add('MainMenu', mainMenu);game.state.start('MainMenu');Thank you for all of your interest. Regards Link to comment Share on other sites More sharing options...
spencerTL Posted October 8, 2014 Share Posted October 8, 2014 Well done. Thanks for showing your solution. Link to comment Share on other sites More sharing options...
Recommended Posts