context.fillStyle不起作用

时间:2017-12-14 01:41:54

标签: javascript canvas

我正在尝试显示图像,但我遇到了context.fillStyle工作的问题。它应该是一个pacman但不能让它工作。能够解决这个问题的任何帮助都将非常感激。

        <canvas> id="canvas" width="600" height="600">
            <p>Sorry, your browser doesnt understand the canvas element</p>
        </canvas>

        <script>
            var canvas;
            var context;
            canvas = document.getelementbyid('canvas');
            context = canvas.getContent('2d');
            function drawCharacter() {
                context.beginPath();
                context.moveTo(118, 118);
                context.lineTo(227, 73);
                context.bezierCurveTo(209, 30, 167, 0, 118, 0);
                context.bezierCurveTo(53, 0, 0.5, 53, 0, 118);
                context.bezierCurveTo(0, 183, 53, 235, 118, 235);
                context.bezierCurveTo(159, 235, 195, 215, 216, 183);
                context.lineTo(118, 118);
                context.closePath();
                context.fillStyle() = "rgb(249, 243, 161)";
                context.fill();
                context.stroke();
                context.beginPath();
                context.arc(118, 60, 10, 0, 2*Math.PI, false);
                context.fillStyle() = "rgb(0, 0, 0)";
                context.fill();
            } 
            drawcharacter();
        </script>

1 个答案:

答案 0 :(得分:1)

CanvasRenderingContext2D.fillStyle是属性,而不是方法。删除parens:

context.fillStyle = "rgb(249, 243, 161)";