espace

how to access game.height before phaser begin ?

Recommended Posts

hi,

i would work with separate files. the problem, i create my sprite config before and i would access the game.height to put them correctly in the screen.

minimum example code 

//parameter.js
var circle;
var circle2;

//proto.js before main.js
var create_circle=()=>{
	circle = game.add.graphics(0, 0);
	circle.beginFill(0xFF0000, 1);
    circle.drawCircle(300, game.height*.3, 100);
} 


//main.js
var config = {
	width: 800,
	height: 800,
	renderer: Phaser.CANVAS,
	antialias: true,
	multiTexture: true,
	state: {
		preload: create,
		update: update
	},
}

let game = new Phaser.Game(config);
var circle;

function create () {
	this.game.scale.pageAlignHorizontally = true;
	this.game.scale.pageAlignVertically = true;
	this.game.scale.refresh();

	circle2 = game.add.graphics(0, 0);
	circle2.beginFill(0xFF0000, 1);

	//HERE IT'S EASY 
    circle2.drawCircle(300, game.height*.3, 100);

    // HERE IT DON'T WORK AND IT'S NORMAL BECAUSE GAME DON'T EXIST 
    //BUT IS THERE A WAY TO ACCESS GAME.HEIGHT ???
    //window.innerHeight is not the same than game.height !

    create_circle()

}

function update () {

}

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.