TuxMG Posted May 16, 2014 Share Posted May 16, 2014 Hi, I would like to make a line shape (with a background color) and have a collision event fire when a sprite is on top of the line shape? How can I do that?shapeGr = game.add.graphics(0, 0); game.physics.enable(shapeGr, Phaser.Physics.ARCADE);shapeGr.moveTo(250, 100);shapeGr.lineTo(250, 0);// Try to overlap:game.physics.arcade.overlap(thing.body, shapeGr, gotHit, null, this);Thanks! Link to comment Share on other sites More sharing options...
juicejerry Posted August 14, 2014 Share Posted August 14, 2014 any answer to this?? Link to comment Share on other sites More sharing options...
lewster32 Posted August 14, 2014 Share Posted August 14, 2014 You can do this a number of ways, with BitmapData (draw the line on the BitmapData instance then use it as the key for a Sprite) like in this example, or simply by adding the Graphics object as a child of the Sprite, like below: shapeGr = game.add.graphics(); shapeGr.moveTo(250, 100); shapeGr.lineTo(250, 0); // Remove the 10 pixel padding added to graphics by default shapeGr.boundsPadding = 0; // Create an empty sprite as a container shapeSprite = game.add.sprite(0, 0); // Add the graphics to the sprite as a child shapeSprite.addChild(shapeGr); // Enable physics on the sprite (as graphics objects cannot have bodies applied) game.physics.enable(shapeSprite, Phaser.Physics.ARCADE); // Overlap should now work game.physics.arcade.overlap(thing.body, shapeSprite, gotHit, null, this); jamespierce and moue 2 Link to comment Share on other sites More sharing options...
Recommended Posts