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

  • Home
  • SEARCH
  • 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 7621567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:13:38+00:00 2026-05-31T04:13:38+00:00

I am writing text to a canvas 3 times in three different places using

  • 0

I am writing text to a canvas 3 times in three different places using a function, Currently the function is parameter-less, but it uses a global variable that is changed between the function calls to indicate the count, which is used to determine the text that is output. It could take a parameter and be used in a loop with a local rather than global variable.

After these three text strings are output to the canvas Which I want to show sequentially…

I then call another function which clears the canvas and shows the end result.

I want all of these to happen sequentially with time between them.

I have tried the setTimeout() and setInterval() and have also tried the pausecomp(ms) function suggested by one responder. NONE have given me the results I desire.

here is the sample of what I am doing…

c=document.getElementById("canvas");
ctx=c.getContext("2d");

function whap(opt)
{
    var comp=Math.floor(Math.random()*3)+1; // determines computer choice
    ctx.fillStyle="#92B9CC";
    ctx.fillRect(0,0, c.width, c.height);

    num = 1;
    goCount();
    sleep(500);
    num = 2;
    goCount();
    sleep(500);
    num = 3;
    goCount();
    sleep(500);

    drawChoice(choice, comp);
}

function goCount()
{
    ctx.fillStyle="#340CF7";
    if(num == 1)
    {
        ctx.fillText("One...", 50, 100);
    }
    else if(num == 2)
    {
        ctx.fillText("Two...", 100, 150);
    }
    else if(num == 3)
    {
        ctx.fillText("Three...", 150, 200);
    }
    else
    {
        ctx.fillText("Go!!", 200, 250);
    }
}

function drawChoice(n, x)
{
    /* this function redraws the canvas the based on the two parameters,
determines whether the player won or lost and fills the canvas 
with the results... drawing the appropriate images onto the canvas 
then filling the canvas with the appropriate text.
    */
}
  • 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-05-31T04:13:39+00:00Added an answer on May 31, 2026 at 4:13 am

    Generally you cannot have blocking calls in js (there are only a few exceptions, but these are not recommended because it will block entire UI). So either you need to work with a deferred objects or you need to use callbacks like this:

    function sleep(next) {
        window.setTimeout(next, 500);
    }
    
    num=1;
    goCount();
    
    sleep(function() {
       num = 2; 
       goCount();
    
       sleep(function() {
           num = 3;
           goCount();
    
           sleep(function() {
               drawChoice(choice, comp);
           });
       });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing text to a page using document.write for a Chrome extension, but the
I'm writing a text editor in gtk+ 2.0 & gtksourceview 2.0. Currently I'm using
I am writing a Text file with php using mysql db fields, which are
i am writing a text editor in gtk 3 using python. in gtk 2
I am writing a text editor in C using gtk+-2.0 & gtksourceview-2.0. I'm trying
I am writing a text editor using gtk+-2.0 & gtksourceview-2.0. I am having trouble
I am writing a text editor and had planned on using the richtextbox control
I am writing a text editor(in java) where I am using a JTextArea for
I have created a text file in Unix environment using Java code. For writing
I have a created text file in unix enviroment using java code. For writing

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.