Pergunta

Estou tentando traçar meu objeto Kinetic Spline com um gradiente em vez de uma cor sólida.No entanto, meu spline está ficando preto.Alguma ideia?

Aqui está meu código:

var stage = new Kinetic.Stage({
    container: 'container',
    width: 578,
    height: 200
  });
var layer = new Kinetic.Layer(); 
var blueSpline = new Kinetic.Spline({
    points: [{
      x: 73,
      y: 160
    }, {
      x: 340,
      y: 23
    }, {
      x: 500,
      y: 109
    }, {
      x: 300,
      y: 109
    }],
    strokeWidth: 10,
    lineCap: 'round',
    tension: 1,
    fillLinearGradientStartPoint: [73, 160],
    fillLinearGradientEndPoint: [300, 109],
    fillLinearGradientColorStops: ['#ff0000', '#00ff00'],
    fillPriority: 'linear-gradient'
  });

  layer.add(blueSpline);
  stage.add(layer);
Foi útil?

Solução

Você pode tentar isto:

var ctx = layer.getContext();
var grad = ctx.createLinearGradient(73, 160, 300, 109);
grad.addColorStop(0, '#ff0000');
grad.addColorStop(1, '#00ff00');

var blueSpline = new Kinetic.Spline({
...
stroke: grad,
...
});

Aqui está um exemplo:http://jsfiddle.net/qK6nq/

Outras dicas

KineticJS não oferece suporte a traços gradientes - apenas preenchimentos gradientes.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top