totallybueno Posted July 22, 2015 Share Posted July 22, 2015 Hi there,I have a basic prototype, it´s a basic plattformer and I have the hero and the platforms working (with tilemaps) At the beginning of the game, I drop the hero on top of a platform and everything works fine I can walk in the platform and drop into a platform below. Also I can jump, but the problem is that I can jump everytime instead of just when I´m touching the floor (basically I can fly!). I´m using the sprite.body.touching.down property but it seems it´s not working at all, even when I´m walking on top of a platform the value of body.touching.down is false (and the physics and working fine) Am I missing something? Should I do "something else"? If it helps, here´s my codecreate: function () { this.game.physics.startSystem(Phaser.Physics.ARCADE) this.game.physics.arcade.gravity.y = 1000; this.cursors = this.game.input.keyboard.createCursorKeys(); this.map = this.add.tilemap("level1") this.map.addTilesetImage("tiles_spritesheet", "gameTiles") this.fondo = this.map.createLayer("fondo") this.bloques = this.map.createLayer("bloques") this.map.setCollisionBetween(1,160, true, "bloques") this.bloques.resizeWorld(); this.hero = this.game.add.sprite(this.game.world.width*0.3, this.game.world.height*0.25, "prota") this.hero.scale.setTo(0.5); this.hero.anchor.setTo(0.5) this.physics.enable(this.hero) this.game.camera.follow(this.hero) }, jump:function(){ console.log(this.hero.body.touching) this.hero.body.velocity.y = -400; }, update:function(){ this.hero.body.velocity.x = 0; this.game.physics.arcade.collide(this.hero, this.bloques) if(this.cursors.right.isDown){ this.hero.body.velocity.x = 300; }else if(this.cursors.left.isDown){ this.hero.body.velocity.x = -300; } if(this.cursors.up.isDown){ this.jump(); } } Link to comment Share on other sites More sharing options...
substandardgaussian Posted July 22, 2015 Share Posted July 22, 2015 I tend to use physics on everything, so I don't have a lot of experience with this, but I believe tile collision properties are Phaser properties that are independent from physics systems like Arcade. You're not setting bodies on any of the tiles, you're just setting flags that the game engine checks independently of physics. Arcade's body.touching cares about Arcade bodies, so from its point of view your sprite isn't actually touching anything. If you want to use Arcade physics, you should set physics bodies on your tiles instead of using the built-in collision properties in Phaser. That should make it work. Link to comment Share on other sites More sharing options...
Noid Posted July 23, 2015 Share Posted July 23, 2015 if(this.cursors.up.isDown){this.jump();} Here it says that whenever up is pressed you call this.jump(); You're not checking whether the hero is touching the floor or not.It should be if (this.cursors.up.isDown && this.hero.body.onFloor() ) { Link to comment Share on other sites More sharing options...
totallybueno Posted July 23, 2015 Author Share Posted July 23, 2015 Thanks for the answers,@Noid, in that function jump() is where I check if the hero´s jumping (not in that code but you can see the console log after all my tests) and the result is the same, the problem is that body.touching.down is false. @substandardgaussian, first of all, awesome nickname XD. I don´t know tilemaps so well, actually is the very first time that I use them, so I´m gonna check stuff about that... any tip? Thanks guys. Link to comment Share on other sites More sharing options...
totallybueno Posted July 23, 2015 Author Share Posted July 23, 2015 @substandardgaussian, shouldn´t be enough with this line? In theory is how you "give the tiles a body"....this.map.setCollisionBetween(1,160, true, "bloques") Link to comment Share on other sites More sharing options...
totallybueno Posted July 23, 2015 Author Share Posted July 23, 2015 I just discovered that it works this way:this.hero.body.blocked.down Link to comment Share on other sites More sharing options...
Recommended Posts