#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0

    Help, Not Drawning Image after ClearRect


    I want to clear my canvas the redraw it -30 pixel on the x axis. When I run it the canvas clears but doesn't redraw the canvas. When i run it without the "clearRect" it works put just draws the images over the current ones. Does anybody know what the problem?
    Thanks in advance

    Code:
    ctx.save();
    ctx.clearRect(0, 0, 480, 400);
    ctx.translate(-30, 0);
    ctx.drawImage(mycanvasvariable, 0, 0);
    ctx.restore();
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,288
    Rep Power
    190
    Try adding your code to a function; then re-trigger your function within an event of a button or link (<a> tag). Then see what the outcome is; I think that may do the trick.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0
    Originally Posted by web_loone08
    Try adding your code to a function; then re-trigger your function within an event of a button or link (<a> tag). Then see what the outcome is; I think that may do the trick.
    Thats how it was being activated in the first place,
    Thanks though
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,288
    Rep Power
    190
    Ok, well..., another way to go; would be to remove the canvas, create a new one, append it to the document, and then re-draw new content to the newly created canvas. The issue your having may be occurring because the canvas and it's content may be cached in the DOM. I maybe wrong, but that's just my hypothesis; about the issue your having.

IMN logo majestic logo threadwatch logo seochat tools logo