1

I'm getting very confused here, though i'm very new to the HTML 5 canvas.

Basically I have this function:

function drawcircle(x,y)
{
    context.save();
    context.strokeStyle = '#00ff00';
    context.fillStyle = '#000000';
    context.lineWidth=10;
    context.beginPath();
    context.arc(x,y,50,0,Math.PI * 2,false)
    context.stroke();
    context.fill();
    context.endPath();
    context.restore();
}

I then try to call it twice like so:

    // call the initialise and draw functions
initialise();
drawcircle(100, 100);
drawcircle(100, 200);

However it will only ever draw the first circle seemingly, whatever order the first circle will be drawn but not the second, how would I go about remedying this?

1 Answer 1

1

It should be closePath(), not endPath(), your function will error before .restore() so it's never called and the second call will happen with state left from previous call.

function drawcircle(x,y)
{
    context.save();
    context.strokeStyle = '#00ff00';
    context.fillStyle = '#000000';
    context.lineWidth=10;
    context.beginPath();
    context.arc(x,y,50,0,Math.PI * 2,false)
    context.stroke();
    context.fill();
    context.closePath(); //Changed
    context.restore();
}

http://jsfiddle.net/kwHT5/

You should always check the javascript console for errors.

Sign up to request clarification or add additional context in comments.

1 Comment

Bah I'm such a fool, Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.