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)
    }


因此,我正在编写一个pong游戏,并尝试创建它,以便一旦有人赢得了比赛,就会显示文字说明哪个玩家获胜。但是,一旦有人赢得了比赛,我所看到的就是黑屏。我认为我已经将问题缩小到了这段代码,但是我不确定出什么问题。有人可以告诉我怎么了吗?

最佳答案



 canvasContext.fillStyle = white;


白色应该是这样的字符串:

 canvasContext.fillStyle = 'white';


请参见Examples以供参考。

07-28 09:21