kpded

Background on game page

Recommended Posts

Hello!

I'm trying to put a background behind the game div in Phaser 3. So that there is my game (960x640) in center of the page and the rest of the page covered with repetitive image

241548194_Screenshotfrom2018-07-2515-42-18.resized.png.17dc5eaa7bd15024201c95ba52ae0835.png

In Phaser 2 I used the following code in my index.html and it worked

<head>
...
<style>
.overlay {		
    background: #acbbbe;
    background-image: url(assets/pageBack.png);
    background-repeat: repeat;
    position:fixed;
    width:100%;
    height:100%;
    top:0px;
    left:0px;
}
.divstyle{
    position: absolute; 
    top: 50%; 
    left: 50%; 
    -webkit-transform: translate(-50%, -50%); 
    transform: translate(-50%, -50%);
}			
</style>
</head>	

	<body>
		<div id="wrapper" class="overlay">
			<div id="gameContainer" class="divstyle"> </div>
		</div>
	</body>
...

Using this snippet together with the following index.js in Phaser 3

const gameConfig = {
	width: 640,
	height: 960,
	scene: SimpleScene,
	parent: 'gameContainer'
};

new Phaser.Game(gameConfig);

Brings the game div element behind the background div element

What does cause that strange behavior? How can one fix that?

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.