LearningPhaser9 Posted July 27, 2015 Share Posted July 27, 2015 (edited) Hmm I not sure why this is occurring. I tried commenting a few lines out. Im not sure what making it this happen. The png file has 4 sprites, but it stays in one stop. <html> <head> <style type="text/css"> body { margin: 0; /*background:url(./assets/backpage.png);*/ } </style> <script type="text/javascript" src="js/phaser.min.js"> </script> <script type="text/javascript"> var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); //game.physics.startSystem(Phaser.Physics.ARCADE); function preload() { // I have loaded my assests here game.load.image('explosions', './assets/explosions.png'); game.load.image('platform', './assets/turtle.png'); game.load.image('sky', './assets/backsky.png'); game.load.image('spike', './assets/spike.png'); game.load.image('mountain','./assets/moutain.png'); game.load.audio('lz', ['assets/Shop - The Legend of Zelda- Ocarina of Time.mp3']); game.load.spritesheet('chicken', './assets/chicken.png', 50, 50); } var player; var platforms; var cursors; var spike; var audio; var s; function create() { game.physics.arcade.collide('chicken','platform'); game.physics.arcade.collide('chicken','spike'); cursors = game.input.keyboard.createCursorKeys(); game.add.sprite(0,0, 'sky'); //game.add.sprite(0,0,'mountain'); player = game.add.sprite(100, game.world.height - 200, 'chicken'); game.physics.arcade.enable(player); // player.body.bounce.y = 0.2; // player.body.gravity.y =300; // player.body.collideWorldBounds = true; //player.animations.add('left', [0,1], 3, true); //player.animations.add('right', [2,3], 3, true); //cursors = game.input.keyboard.createCursorKeys(); // moutain sprite // spike sprite // spike group spike = game.add.group(); spike.enableBody = true; var floor = spike.create(500, game.world.height - 120, 'spike'); floor.scale.setTo(0.75,0.75); floor.body.immovable = true; var trick = spike.create(420, game.world.height - 120, 'spike'); // spike create var bottom = spike.create(600,550,'spike'); bottom.body.immovable = true; var deathd = spike.create (345,550,'spike'); bottom.body.immovable = true; //var death = spike.create( 355,550,'spike'); // bottom.body.immovable = true; var place = spike.create( 355,550,'spike'); bottom.body.immovable = true; // var deatha = spike.create ( 375,550,'spike'); //bottom.body.immovable = true; var deathb = spike.create ( 385,550,'spike'); bottom.body.immovable = true; // var deathc = spike.create (395,550,'spike'); bottom.body.immovable = true; var deathd = spike.create ( 550,550,'spike'); bottom.body.immovable = true; var deathe = spike.create (650,550, 'spike'); bottom.body.immovable = true; var deathf = spike.create (700,550, 'spike'); bottom.body.immovable= true; var deathg = spike.create (750,550,'spike'); bottom.body.immovable = true; // platform sprite platform = game.add.group(); platform.enableBody = true; // creating platform belongs here var ground = platform.create(0, game.world.height - 64, 'platform'); ground.scale.setTo(2,2); ground.body.immovable = true; var ledge = platform.create(-150,250,'platform'); ledge.body.immovable = true; var rside = platform.create(150,300, 'platform'); rside.body.immovable = true; var morerside = platform.create(400,500, 'platform'); morerside.body.immovable = true; var rsidea = platform.create( 750,350, 'platform'); rsidea.body.immovable = true; // platform.body.immovable = true; // moutain sprite //mountain = game.add.group(); // mountain.enablebody = true; //var mou = mountain.create(-1000, game.world.height - 500, 'mountain'); // music // music = game.add.audio('lz'); // music.play(); // s = game.add.sprite(game.world.centerX, game.world.centerY, 'lz'); // s.anchor.setTo(0.5, 0.5); } function update() { game.physics.arcade.collide(player,platform); game.physics.arcade.collide(player,spike); cursors = game.input.keyboard.createCursorKeys(); game.physics.arcade.enable(player); player.body.bounce.y = .2; player.body.gravity.y = 50; player.body.collideWorldBounds = true; //player.animations.add('left', [0,1], 10, true); //player.animations.add('right', [2,3], 10, true); player.body.velocity.x = 0; if (cursors.left.isDown) { // Move to the left player.body.velocity.x = -120; player.animations.play('left'); } else if (cursors.right.isDown) { // Move to the right player.body.velocity.x = 120; player.animations.play('right'); } else { // Stand still player.animations.stop(); player.frame = 2; } // Allow the player to jump if they are touching the ground. if (cursors.up.isDown && player.body.touching.down) { player.body.velocity.y = -120; } } </script> </head> <body> </body> </body> </html> Edited July 28, 2015 by rich Formatted source code Link to comment Share on other sites More sharing options...
rich Posted July 28, 2015 Share Posted July 28, 2015 Wow, so many mistakes in such a small piece of code Right now you want to get rid of ALL of these lines from the update function: cursors = game.input.keyboard.createCursorKeys(); game.physics.arcade.enable(player); player.body.bounce.y = .2; player.body.gravity.y = 50; player.body.collideWorldBounds = true; //player.animations.add('left', [0,1], 10, true); //player.animations.add('right', [2,3], 10, true); Link to comment Share on other sites More sharing options...
CodeToWin Posted July 28, 2015 Share Posted July 28, 2015 check out some tutorials... it's easier to build a few games, while your hand is being held,and then move on to doing your own thing. I suggest the first game on the Phaser website, then something like my SpaceShooter tutorial at codetowin.io and/or the flappy birds tutorial by lessMilk. If you still want more, check out the tutorials thread and see what interests you Link to comment Share on other sites More sharing options...
Recommended Posts