Jump to content

touch based bitmap data collision


doyouknowyou
 Share

Recommended Posts

I'm drawing a line from one game pointer to another using bitmap data and it works pretty well, however I'm trying to enable a body and have it collide with another object. The bitmap line immediately takes up the entire screen, allowing no space for anything else to move. Using overlap instead of collide doesn't help either.

Is there a better way to approach this, where only the drawn pixels are treated as the body?

 

Thanks for any help!

draw(){		let gameX = game.globals.SAFE_ZONE_WIDTH  * 0.5	let gameY = game.globals.SAFE_ZONE_HEIGHT * 0.5	this.line = game.add.bitmapData(gameX*2 ,gameY*2);	this.spriteLine = game.add.sprite(0, 0, this.line); 	game.physics.enable(this.spriteLine, Phaser.Physics.ARCADE);},drawLine(){	this.line.clear();	this.line.ctx.beginPath();	this.line.ctx.strokeStyle = "white";	this.line.ctx.lineCap = 'round';	this.line.ctx.moveTo(10, 10);	this.line.ctx.lineTo(game.input.x , game.input.y);	this.line.ctx.lineWidth = 12;	this.line.dirty = true;	this.line.ctx.stroke();	this.line.ctx.closePath();	this.line.render();},
update(){	game.physics.arcade.collide(createBall.ball, createLine.spriteLine, this.gameFail, null, this);	if (game.input.pointer1.isDown && game.input.pointer2.isDown) {		createLine.drawLine();	} else {		createLine.destroyLine();	}}
Link to comment
Share on other sites

arcade physics is completely modular - the physics bodies are rectangles and can't be drawn lines or polygonal shapes (doesn't matter if the texture of the sprite is). The physics body is acting like it takes up the entire screen because the rectangular physics body representation of your sprite has a width/height large enough. You might have better luck with P2 physics which does have support for polygonal physics bodies. Also, when you're doing this sort of thing, it's wise to enable debugging on your physics bodies so you can actually see them. In render():

game.debug.body(sprite, 'red', false);
Link to comment
Share on other sites

Thanks for replying!
 

I've had a look into P2 physics and polygonal physics look like they could be the solution, however I'm unsure if this would work as the shape will be constantly updating. I'm still a little new to phaser, would you be able to give a little more info on how to approach this?

 

Much appreciated!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...