更改路径颜色时打印文本

时间:2016-03-10 20:00:09

标签: javascript paperjs

我正在尝试制作一个你需要点击圈子的游戏。单击时,每个圆圈都会改变颜色。我希望它在所有圈子被点击时说“恭喜”,但此刻它在按下一个圈子后显示'恭喜'。知道如何解决这个问题吗?

var text = new PointText(view.center);
text.content = 'Congrats';
text.visible = false;
text.style = {
    fontFamily: 'Courier New',
    fontWeight: 'bold',
    fontSize: 100,
    fillColor: 'black',
    justification: 'center'
}

for (l = 0; l < balls.length; l++) {
    balls[l].onClick = function(event) {
        counter++



    this.fillColor = '#860d2b';
    var areAnyCoral = false;
    for (var j = 0; j < balls.length; j++) {
        if (balls[j].fillColor === 'coral') {
            areAnyCoral = true;
        }
    };
    if (areAnyCoral === false) {
        text.visible = true;
    }

}

}

2 个答案:

答案 0 :(得分:1)

我认为您应该针对counter属性检查text.visible,而不是填充颜色。这有意义吗?

var counter = 0;
var ball1 = {
  color: "notCoral"
};

var ball2 = {
  color: "notCoral"
}

var balls = [ball1, ball2];

balls.forEach(function(ball) {
  ball.onClick = function(event) {
    if (ball.color == "notCoral") {
      ball.color = "coral";
      counter++;
    }

    if (counter == balls.length) {
      text.visible = true;
    }
  }
});

答案 1 :(得分:0)

实际上,您需要更改:

[GAURLProtocol injectURL:@"http://example.com/video.mp4" cookie:@"cookie=f23r3121"];
MPMoviePlayerController * moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:@"http://example.com/video.mp4"];
[moviePlayer play];

为:

balls[j].fillColor === 'coral';

因为fillColor是一个对象,你需要使用“equals”方法来比较字符串颜色:http://paperjs.org/reference/color/#equals-color