druphoria Posted July 19, 2014 Share Posted July 19, 2014 I've implemented some code for a moving platform. The platform itself is a sprite, defined as follows:this.movingPlatforms = game.add.group(); platform = this.movingPlatforms.create(8 * TILE_SIZE, 10 * TILE_SIZE, 'platform'); platform.name = 'platformOne'; this.game.physics.arcade.enable(platform); platform.leftBounds = platform.body.x; platform.rightBounds = platform.body.x + 200; platform.body.velocity.x = 100; platform.body.immovable = true;I amended the code for jumping to detect a collision on the bottom of the sprite. For some reason, the jump wasn't working when my main guy was standing on a platform. I was trying to set his velocity to -300 but he wouldn't move at all. The jump function would still get triggered - in fact, it'd be triggered repeatedly each time I pressed the jump button but with no actual movement. I managed to get it working in a very strange way - before applying the negative velocity to the sprite upon pressing the jump button, I first raised him 1 pixel above the platform by decrementing his y position. The negative velocity is applied immediately after. Suddenly it started working: if (this.jumpButton.isDown && (this.sprite.body.onFloor() || this.sprite.body.wasTouching.down === true)){ console.log("jumping!"); this.sprite.body.position.y -= 1; this.sprite.body.velocity.y = -300; this.jumpSound.play(); }Any idea why this is going on? Link to comment Share on other sites More sharing options...
Recommended Posts