Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- </head>
- <body>
- <script>
- var config = {
- type: Phaser.AUTO,
- backgroundColor: 0xCCFFFF ,
- width: 600,
- height: 600,
- physics: {
- default: 'arcade'
- },
- scene: {
- preload: preload,
- create: create,
- update: update
- }
- };
- var gamePiece;
- var keyInputs;
- var game = new Phaser.Game(config);
- var upKey;
- function preload(){
- this.load.spritesheet('gamePiece', 'img/spriteSheet.png', {
- frameWidth: 60,
- frameHeight: 60
- });
- }
- function create(){
- this.anims.create({
- key: "spin",
- frameRate: 4,
- frames: this.anims.generateFrameNumbers("gamePiece", {start: 0, end:11}),
- repeat: -1
- });
- this.anims.create({
- key: "up",
- frameRate: 2,
- frames: this.anims.generateFrameNumbers("gamePiece", {start: 0, end:2}),
- repeat: -1
- });
- this.anims.create({
- key: "right",
- frameRate: 2,
- frames: this.anims.generateFrameNumbers("gamePiece", {start: 3, end:5}),
- repeat: -1
- });
- this.anims.create({
- key: "down",
- frameRate: 2,
- frames: this.anims.generateFrameNumbers("gamePiece", {start: 6, end:8}),
- repeat: -1
- });
- this.anims.create({
- key: "left",
- frameRate: 2,
- frames: this.anims.generateFrameNumbers("gamePiece", {start: 9, end:11}),
- repeat: -1
- });
- gamePiece = this.add.sprite(270, 450, 'gamePiece');
- gamePiece.anims.play("spin");
- keyInputs = this.input.keyboard.createCursorKeys();
- leftKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
- rightKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
- upKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
- downKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
- }
- function update(){
- if(keyInputs.left.isDown){
- gamePiece.x = gamePiece.x - 2;
- }
- if(keyInputs.right.isDown){
- gamePiece.x = gamePiece.x + 2;
- }
- if(keyInputs.up.isDown){
- gamePiece.y = gamePiece.y - 2;
- }
- if(keyInputs.down.isDown){
- gamePiece.y = gamePiece.y + 2;
- }
- if(Phaser.Input.Keyboard.JustDown(leftKey)){
- gamePiece.anims.play("left");
- }
- if(Phaser.Input.Keyboard.JustDown(rightKey)){
- gamePiece.anims.play("right");
- }
- if(Phaser.Input.Keyboard.JustDown(upKey)){
- gamePiece.anims.play("up");
- }
- if(Phaser.Input.Keyboard.JustDown(downKey)){
- gamePiece.anims.play("down");
- }
- if(Phaser.Input.Keyboard.JustUp(leftKey)){
- gamePiece.anims.play("spin");
- }
- if(Phaser.Input.Keyboard.JustUp(rightKey)){
- gamePiece.anims.play("spin");
- }
- if(Phaser.Input.Keyboard.JustUp(upKey)){
- gamePiece.anims.play("spin");
- }
- if(Phaser.Input.Keyboard.JustUp(downKey)){
- gamePiece.anims.play("spin");
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement