赢得乒乓球比赛后不会出现文字

时间:2018-06-16 02:09:29

标签: javascript html5 html5-canvas

function drawEverything(){
    //next line blacks out screen
    colorRect(0,0, canvas.width,canvas.height,'black');
    if(showingWinScreen){
        canvasContext.fillStyle = white;
        if(player1Score >= winningScore){
canvasContext.fillText("Left Player won!",350,200);
        }else if(player2Score >=winningScore){
canvasContext.fillText("Right Player won!",350,200)
            }

        canvasContext.fillText( 'click to continue', 350,500)
        return;
        }

    //this is left player paddle
    colorRect(0,paddle1Y,paddleThick,PADDLE_HEIGHT,'white');

    //this is right player paddle
    colorRect(canvas.width- paddleThick,paddle2Y,paddleThick,PADDLE_HEIGHT,'white');

    //next line draws a ball
    colorCircle(ballX,ballY,10,'white');

    canvasContext.fillText( player1Score, 100,100);
    canvasContext.fillText( player2Score, 700,100)
    }

所以我正在编写一个乒乓球游戏,我正在尝试创建它,以便一旦某人赢得游戏,就会显示文字说出哪个玩家赢了。然而,一旦有人赢了比赛,我看到的只是黑屏。我想我已经将问题缩小到这段代码,但我不确定是什么问题。有人能告诉我什么是错的吗?

1 个答案:

答案 0 :(得分:1)

 canvasContext.fillStyle = white;

white应该是这样的字符串:

 canvasContext.fillStyle = 'white';

请参阅Examples以供参考。