Skip to content

Instantly share code, notes, and snippets.

@unstoppablecarl
Created February 27, 2013 00:11
Show Gist options
  • Save unstoppablecarl/5043614 to your computer and use it in GitHub Desktop.
Save unstoppablecarl/5043614 to your computer and use it in GitHub Desktop.
var mX = ig.input.mouse.x,
mY = ig.input.mouse.y,
spawnX = this.pos.x + this.size.x/2,
spawnY = this.pos.y + this.size.y/2,
r = Math.atan2(mY - spawnY, mX - spawnX),
directionX = Math.cos(r) * 50,
directionY = Math.sin(r) * 50;
ig.system.context.strokeStyle = 'rgba(0,255,0,.5)';
ig.system.context.beginPath();
ig.system.context.moveTo(spawnX,spawnY);
ig.system.context.lineTo(mX, mY);
ig.system.context.stroke();
ig.system.context.beginPath();
ig.system.context.strokeStyle = 'rgba(255,0,0,.5)';
ig.system.context.moveTo(spawnX,spawnY);
ig.system.context.lineTo(directionX, directionY);
ig.system.context.stroke();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment