Skip to content

Instantly share code, notes, and snippets.

@zardilior
Created April 4, 2020 03:33
Show Gist options
  • Save zardilior/47eca153899cc7989b044dd2a6d684c9 to your computer and use it in GitHub Desktop.
Save zardilior/47eca153899cc7989b044dd2a6d684c9 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.15.1/dist/phaser-arcade-physics.min.js"></script>
</head>
<body>
<script>
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var game = new Phaser.Game(config);
var image;
var image2;
var image3;
function preload() {
// load an image
// here we load an image and give it a name/alias
this.load.image('background','./download.jpeg');
}
function create() {
// add it to our game
// this.add.image(x,y,imageName)
// x is the horizontal, left to right
// y is the vertical, top to bottom
// and imageName is the alias of the image
image = this.add.image(0,200,'background');
image2 = this.add.image(0,300,'background');
image3 = this.add.image(0,400,'background');
}
function update() {
// change its position every frame
if( image.x > 600) {
image.x = 0;
}
if( image2.x > 600) {
image2.x = 0;
}
if( image3.x > 600) {
image3.x = 0;
}
image.x += 2;
image2.x += 5;
image3.x += 6;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment