Jump to content

Uncaught TypeError: Cannot read property 'hasLoaded' of undefined


yigitozdemir
 Share

Recommended Posts

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

I've never used a spritesheet for buttons but shouldn't the preload line define the dimensions and number of frames?  eg

game.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

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

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...