Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8221375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:53:55+00:00 2026-06-07T13:53:55+00:00

I have this frame animation where each frame is called at every 1/30s. Canvas

  • 0

I have this frame animation where each frame is called at every 1/30s.

Canvas is simply not being cleared properly. Why?

Here is the code:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>

<script src="http://code.createjs.com/easeljs-0.4.2.min.js" ></script>
<script src="http://code.createjs.com/tweenjs-0.2.0.min.js" ></script>

<script>
var canvas;
var stage;
var screen_width;
var screen_height;
var bmpAnimation;

// this is a list of keyframes for each image parameter to be animated
var beachX = new Array(102,130,140,200, 233, 211, 133, 455,222);
var beachY = new Array(52,120,240,400, 102,130,140,200, 233);
var beachRotation = new Array(102,30,140,200, 33, 211, 133, 355,222);
var beachOpacity = new Array(0, 0.5, 1, 0.3, 0.8, 0.3, 0.9, 0.3, 1);
var beachScaleX = new Array(0, 0.5, 0.7, 0.3, 0.8, 1, 0.9, 0.2, 1);
var beachScaleY = new Array(0.3, 0, 0.5, 0.7, 0.3, 0.8, 1, 0.9, 1);


var index = 0;

var beach;


var context;
var interval;

window.onload = init;




function make_beach()
{
  beach = new Image();
  beach.src = "beach.png"; // this can be any image that is large (at least 600 x 600 pixels)
  beach.onload = function(){
    context.drawImage(beach, 70,120);
  }
}




function init() {
        canvas = document.getElementById("myCanvas");
    context = canvas.getContext('2d');
    context.save();

    make_beach();

    interval = setInterval("tick()",33);

    stage = new Stage(canvas);

}



function degreesToRadians(num) {
    return num * 0.0174532925199432957;
}



function tick() {

    var numberOfFrames = beachX.length;
    if (index > (numberOfFrames -1)) {
            clearInterval (interval); // cancel the timer
        return;
    }

    context.restore();

    context.globalAlpha = 1;
    context.clearRect(0, 0, canvas.width, canvas.height);


    var beachMiddleX = beach.width * 0.5;
    var beachMiddleY = beach.height * 0.5;
    context.translate(beachX[index] + beachMiddleX, beachY[index] + beachMiddleY);
    context.scale(beachScaleX[index], beachScaleY[index]);
    context.rotate(degreesToRadians(beachRotation[index]));
    context.globalAlpha = beachOpacity[index];
    context.translate(-beachMiddleX, -beachMiddleY);
    context.drawImage(beach, beachX[index], beachY[index]);
    context.restore();

    index ++;
}

</script>
</head>

<body>
<div class="description">

    </div>
    <div class="canvasHolder">
        <canvas id="myCanvas" width="1024" height="768" style="background-color:#FFFFFF">
            Your browser doesn't support canvas. Please download a modern browser 
        </canvas>
    </div>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:53:58+00:00Added an answer on June 7, 2026 at 1:53 pm

    Well the first thing that looks extremely weird is that you have a single call to context.save in your init function, with no matching call to restore. This is bad.

    Then in your tick function you have two calls to restore!

    So your program is doing save once, then restore a million times. Whatever you’re trying to do that is certainly not what you want.

    Here is your code with that fixed and the timer slowed down a lot. It seems to do something, though I don’t know what your intent is here so its hard to say if its what you want or not:

    http://jsfiddle.net/simonsarris/LJQpM/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 10 XAML files, each contaning a frame of an animation (they were
I am drawing a frame by frame animation to a canvas and I have
I have a Property File like this: frame.server.dev=mark.is.cool frame.server.test=chris.is.cool frame.server.qa=mitch.is.cool frame.server.prod=cory.is.cool I need to
Hi i have a div as like that This is Frame a div This
I have a data.frame from this code: my_df = data.frame(read_time = c(2010-02-15, 2010-02-15, 2010-02-16,
I have a list within a data frame (in this example, df$candpct ), and
I have a data frame with gaps like this: Var1 Var2 Var3 1 NA
I have a data.frame that looks like this: > head(ff.df) .id pio caremgmt prev
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame in R that looks like this: > TimeOffset, Source,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.