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

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

  • Recently Browsing   0 members

    No registered users viewing this page.