Jump to content

Platform Nudging?


RyanTheBoy
 Share

Recommended Posts

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...