-4

I want to set an image instead of painting the ball

My code is the following

  ballPainter = {
      BALL_FILL_STYLE: 'rgb(255,0,50)',
      BALL_STROKE_STYLE: 'rgb()',

      paint: function (ball, context) { 
         var imageObj = new Image();

         context.save();

         context.shadowColor = undefined;
         context.lineWidth = 2;
         context.fillStyle = this.BALL_FILL_STYLE;
         context.strokeStyle = this.BALL_STROKE_STYLE;

         context.beginPath();
         context.arc(ball.left, ball.top,
                     ball.radius, -1, Math.PI*2, false);

         context.clip();
         context.fill();
         context.stroke();
         context.restore();
      }
    },
Spokey
  • 10,974
  • 2
  • 28
  • 44

1 Answers1

0

You might want to check http://www.w3schools.com/tags/canvas_drawimage.asp

I'm not sure if you can crop an image to a cricle though (maybe if the image has a transparant background)

*edit apperently you can HTML5 Canvas - Fill circle with image

Community
  • 1
  • 1
dwana
  • 413
  • 3
  • 13