noodlesdefyyou Posted February 16, 2014 Share Posted February 16, 2014 I've finally figured out collision! I'm going through and setting vertex points for my polygons, then added render: render to the var game line at the very top. function render() { game.debug.renderPhysicsBody(player.body); //game.debug.renderPhysicsBody(Drone1.body); //game.debug.renderPhysicsBody(pBlasters.body); //game.debug.renderPhysicsBody(eBlasters.body); } I was able to get my player polygon to display perfectly. However, when I try to display another polygon (uncomment that second line), it tells me 'TypeError: body is undefined phaser.js 37799'. Drone1 is the variable i've applied the polygon to. I've even gone and renamed 'Drone1' to anything else it could possibly be, and whenever I change it, I get the 'x is not defined' error. So I know I have the right variable. The only thing I can think of is Drone1 is a created group, instead of an individual sprite, which is this code: function createDrone1() { for (var y = 0; y < 1; y++) { for (var x = 0; x < 10; x++) { var drones1 = Drone1.create(x * 32, y * 50, 'drone1'); drones1.anchor.setTo(0, 0); drones1.body.setPolygon(1, 14, 11, 17, 11, 2, 21, 2, 21, 17, 31, 14, 31, 42, 29, 49, 27, 35, 22, 30, 16, 36, 10, 30, 5, 35, 3, 50, 1, 39); } } } Assuming this code is correct, it should apply that polygon to each created sprite. Am I overlooking something here? Why am I unable to display a second debug render? Link to comment Share on other sites More sharing options...
rich Posted February 16, 2014 Share Posted February 16, 2014 In the code above you should be doing:game.debug.renderPhysicsBody(drone1.body)because you can't call render body on a Group, only a Sprite instance. Link to comment Share on other sites More sharing options...
noodlesdefyyou Posted February 16, 2014 Author Share Posted February 16, 2014 that returned an error of 'drone1 is undefined'. does this also mean im not able to set the polygon like that from inside the createDrone1 function? would i need to write it like this in the create function? drone1.anchor.setTo(0, 0);drone1.body.setPolygon(points); Link to comment Share on other sites More sharing options...
rich Posted February 16, 2014 Share Posted February 16, 2014 Sorry typo in my reply, it was drones1, not drone1. Either way you have to pass a Sprite to that function, not a Group. Link to comment Share on other sites More sharing options...
Recommended Posts