RyanTheBoy Posted February 7, 2014 Share Posted February 7, 2014 Yo guys, weird issues again! I started working on the Player and Level logic while I wait on the fix for the Timer class. everything is working as expected so far except for one small glitch: when the Player sprite strikes the left side of one of my scrolling Platforms, the platform nudges slightly to the right before continuing on to the left side. (Essentially I am programming an infinite runner, Canabalt-style game.) I can only guess it is because I am setting both player-run-speed and platform-scroll-speed using their body.velocity.x properties. Here first is my Level class...~~~/* LEVEL.JS/**********//* Contains Level class. Responsible/* for loading level platforms and /* related level items./**********/ Level = function(game) {this.game = game;this.platforms = null;}; Level.prototype = {preload: function() {// Load the background image.this.game.load.image('sky', 'assets/sky.png'); // Load the platform image.this.game.load.image('ground', 'assets/ground.png');},create: function() {// Place background first(lowermost layer).this.game.add.sprite(0, 0, 'sky'); // Initialize this.platforms group to push/pop platforms.this.platforms = this.game.add.group(); // Place the initial platform ground. this.platforms.create(64, this.game.world.height - 96, 'ground'); // Place the second platform.this.platforms.create(this.game.world.width + 64, this.game.world.height - (Math.floor(Math.random() * 4) * 32 + 32),'ground');},update: function() {if (this.platforms.getAt(0).x <= -736) {this.platforms.getAt(0).destroy(); this.platforms.create(this.game.world.width + 64, this.game.world.height - (Math.floor(Math.random() * 4) * 32 + 32), 'ground');} this.platforms.setAll('body.velocity.x', SPEED);this.platforms.setAll('body.immovable', true);}};~~~ And here is my Player class... ~~~/* PLAYER.JS/**********//* Contains Player class. Responsible/* for creating the player, applying/* proper physics, and binding all of/* the controls. /**********/ Player = function(game) {this.game = game;this.sprite = null;}; Player.prototype = {preload: function() {// Load up a spritesheet for The Dude.this.game.load.spritesheet('dude', 'assets/dude.png', 32, 48);},create: function() {// Add The Dude to the game. this.sprite = this.game.add.sprite(128, this.game.world.height - 160, 'dude'); // Apply some phsyics to the dude.this.sprite.body.gravity.y = 400; // Animate the running of The Dude. this.sprite.animations.add('run', [5, 6, 7, 8], 10, true);this.sprite.animations.play('run');},update: function() {this.game.physics.collide(this.sprite, level.platforms); if (this.sprite.body.touching.down) {this.sprite.body.velocity.x = -SPEED;} console.log(this.sprite.body.touching.down);}};~~~ Thanks for the helps! Link to comment Share on other sites More sharing options...
rich Posted February 7, 2014 Share Posted February 7, 2014 Why are your platforms set to immovable false in the update function? Also in what sequence / order are you colliding them? It sounds like it's a separation issue so far. BTW you can wrap code in code tags in the forum Link to comment Share on other sites More sharing options...
RyanTheBoy Posted February 7, 2014 Author Share Posted February 7, 2014 Why are your platforms set to immovable false in the update function? Where? I don't see where they are set to false anywhere. Also in what sequence / order are you colliding them? I'm not sure I understand. The collisions are tested in the Player.update() function. The Level(and subsequently level.platforms) is rendered first, followed by the player. I tried swapping the order their create/update functions were called but it didn't make any difference. EDIT: I have fixed this issue but have new problems, found in this new topic! Link to comment Share on other sites More sharing options...
Recommended Posts