-3

I am making a shooter simulator(ish). I have a silhouette of a person with a white background. I have it so you can shoot it. I would like the bullets to stop at the beginning of the sillhouette. You can see it here:

codepen.io/TheAndersMan/pen/WRNEmR?editors=0011

Feel free to change any of the code. Thanks in advance!

TheAndersMan
  • 354
  • 2
  • 14

1 Answers1

2

Try using this code from here.

Version without jQuery here:

img = document.getElementById("image")
output = document.getElementById("output")

img.onmousemove = function(e) {

  if (!this.canvas) {
    this.canvas = document.createElement('canvas');
    this.canvas.width = this.width;
    this.canvas.height = this.height;
    this.canvas.getContext('2d').drawImage(this, 0, 0, this.width, this.height);
  }

  var pixelData = this.canvas.getContext('2d').getImageData(event.offsetX, event.offsetY, 1, 1).data;

  output.innerHTML = 'R: ' + pixelData[0] + '<br>G: ' + pixelData[1] + '<br>B: ' + pixelData[2] + '<br>A: ' + pixelData[3];

};

Don't use images from other sites as it might be blocked.

Update: code without almost any jQuery here. Update coming.

Community
  • 1
  • 1
Chris Happy
  • 6,566
  • 1
  • 20
  • 43