Jump to content

States - functions not defined


3ddy
 Share

Recommended Posts

Hello,

I have just began my adventure with states in Phaser (using Phaser for about a month). I have a problem that any custom function I add to my state is not defined (can't be used) however there is a definition of that function (was trying to put it in different places also). Here is my sample code:

 

index.html

<html>	<head>	<style type="text/css">		body{			background: #ffffff;			padding:0px;			margin:0px;		}	</style>	<script src="phaser.min.js"></script>	<script src="plugins/CanvasInput.min.js"></script>     <!--<script src = "game.js"></script>-->	 <script src = "js/preload.js"></script>	 <script src ="js/intro.js"></script>	</head>	<body>		<script type="text/javascript">			var game = new Phaser.Game(1920, 1080);			game.state.add('Preload', MyGame.preload)			game.state.add('Intro', MyGame.intro);			game.state.add('Office', MyGame.office);			game.state.start('Preload');		</script>	</body></html>

preload.js

var MyGame = {};MyGame.preload = function (game) {    };MyGame.preload.prototype = {        preload: function () {        game.load.image('loadingBackground', 'BG/start.jpg');        game.load.image('officeBackground', 'BG/szukaj_warstwa_1.jpg');		game.load.atlasJSONHash('aml_1', 'aml_1.png', 'aml_1.json');    },        create: function () {        //goFullScreen();        this.state.start('Intro');    },    };

intro.js

MyGame.intro = function (game) {    this.background;    this.character;};MyGame.intro.prototype = {    create: function () {        this.background = this.add.sprite(0, 0, 'loadingBackground');        this.character = game.add.sprite(game.world.centerX, game.world.centerY, 'aml_1', 'aml_avatar_hindus.jpg');        var left = game.add.sprite(game.world.centerX-232, game.world.centerY - 200, 'aml_1', 'strzalka_lewo.png');        var right = game.add.sprite(game.world.centerX+200, game.world.centerY - 200, 'aml_1', 'strzalka_prawo.png');        this.character.anchor.setTo(0.5,0.5);        var startBtn = game.add.sprite(game.world.centerX, game.world.centerY+300, 'aml_1', 'play.png');        startBtn.anchor.set(0.5);        startBtn.inputEnabled = true;        startBtn.events.onInputDown.add(startClicked, this);                game.scale.pageAlignHorizontally = true;		game.scale.pageAlignVertically = true;		// using RESIZE scale mode		game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;		game.scale.setScreenSize(true);       },        startClicked: function() {        this.state.start('Office');    }    };

Error that i get when running:

"Uncaught ReferenceError: startClicked is not defined" in line startBtn.events.onInputDown.add(startClicked, this); of intro.js

Are there some other basic errors that make my code not working? Any help would be appreciated.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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