Sign in to follow this  
Soule

Passing variables when changing states/global variables?

Recommended Posts

Hi,

 

I was wondering if there's any way to pass variables when you change states, or if it's possible to set global variables?

 

I'm using codevinsky's generator (https://github.com/codevinsky/generator-phaser-official), if it makes any difference.

 

Specifically, I want to tell my Game scene what difficulty level to use when the user picks it in the intro scene.

 

Thanks

Share this post


Link to post
Share on other sites

there's a specific example of setting a game wide accessible variable in the Phaser mobile template that allows them to be accessible throughout the game but not pollute the global scope.

https://github.com/photonstorm/phaser/blob/master/resources/Project%20Templates/Full%20Screen%20Mobile/src/Boot.js

Look towards the top of the code.

Share this post


Link to post
Share on other sites

Sorry - I've been too simplistic.  

 

Basicgame is global but what I meant by not polluting the global scope is that Basicgame.score is less likely to conflict with anything than if you just had a globally scoped variable called score which could feasibly be used by another script on the page.

Share this post


Link to post
Share on other sites

In the index.html put the variable as

<html lang="en"> 
<head>
	<meta charset="UTF-8" />
	<title>Your Game</title>
	
	<script type="text/javascript" src="code/phaser.min.js"></script>
	<script type="text/javascript" src="code/Level1.js"></script>
</head>
<body>
<script type="text/javascript">
var game = new Phaser.Game(1100, 550, Phaser.AUTO);
var game.variable = 0930211
</script>
</body>
</html> 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.