PhasedEvolution Posted October 17, 2016 Share Posted October 17, 2016 I have created a simple ground floor as bmd sprite and a player circle bmd sprite. I am having trouble detecting the collision between the floor and the player and when I set the player sprite collideworldbounds property to true the player gets stuck in the upper corner and doesn't fall. Why is that? // global vars var elements_group; var players_group; // Inside create function map_elements_group = game.add.group(); players_group = game.add.group(); game.world.setBounds(0, 0, 500, 200); var player = new Player(300,100); var map = new Map(); // Inside Update function game.physics.arcade.collide(players_group,map_elements_group,playerMapCollision); //console.log("I GET FALSE ",game.physics.arcade.collide(players_group,map_elements_group,playerMapCollision)); var Map = function () { var floor_bmd = game.add.bitmapData(1000, 500); floor_bmd.ctx.beginPath(); floor_bmd.ctx.rect(0, game_height - 100, 1000, 100); floor_bmd.ctx.fillStyle = '#4488AA'; floor_bmd.ctx.fill(); var floor = game.add.sprite(0,0,floor_bmd, 0); game.physics.arcade.enable(floor); floor.body.immovable = true; floor.body.allowGravity = false; } var Player = function (x,y) { this.bmd = game.add.bitmapData(1000, 500); this.bmd.circle(30,30,30,"#E5E4E2"); this.sprite = game.add.sprite(x,y,this.bmd,0,players_group); game.physics.arcade.enable(this.sprite); this.sprite.body.allowGravity = true; this.sprite.body.gravity.y = 800; this.sprite.body.bounce.setTo(0.9, 0.9); //this.sprite.body.collideWorldBounds = true; //When I do this my player gets stuck in the upper corner and doesnt move or fall this.cursors = game.input.keyboard.createCursorKeys(); } Link to comment Share on other sites More sharing options...
samme Posted October 17, 2016 Share Posted October 17, 2016 I think the player body (1000 × 500) is larger than the world (500 × 200) so it's getting trapped. You can use smaller bitmaps for the player and floor: http://codepen.io/anon/pen/NRLQLK?editors=0010 PhasedEvolution 1 Link to comment Share on other sites More sharing options...
PhasedEvolution Posted October 18, 2016 Author Share Posted October 18, 2016 8 hours ago, samme said: I think the player body (1000 × 500) is larger than the world (500 × 200) so it's getting trapped. You can use smaller bitmaps for the player and floor: http://codepen.io/anon/pen/NRLQLK?editors=0010 Oh nice ! Thank you. Do you know how I can make my bmd circular and not squared so it can be the same size as the drawn circle? Link to comment Share on other sites More sharing options...
samme Posted October 18, 2016 Share Posted October 18, 2016 The bitmap must be rectangular but you can make the physics body circular: http://codepen.io/anon/pen/ORBvKv?editors=0010 Link to comment Share on other sites More sharing options...
PhasedEvolution Posted October 18, 2016 Author Share Posted October 18, 2016 1 hour ago, samme said: The bitmap must be rectangular but you can make the physics body circular: http://codepen.io/anon/pen/ORBvKv?editors=0010 isn't the physics body still squared? Link to comment Share on other sites More sharing options...
samme Posted October 18, 2016 Share Posted October 18, 2016 Guess I forgot to save: http://codepen.io/anon/pen/ORBvKv?editors=0010 PhasedEvolution 1 Link to comment Share on other sites More sharing options...
Recommended Posts