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 6587813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:57:59+00:00 2026-05-25T16:57:59+00:00

I am currently doing redraws like this: This works fine, except once in a

  • 0

I am currently doing redraws like this:

This works fine, except once in a while the character sprite will flash. This happens enough to be a pretty big annoyance. How should I do this more efficiently? I also tried changing the redraw frequency. Higher frequencies exacerbated the problem while lower frequencies are not fast enough for graphical reasons.

init()
{
//stuff
    return setInterval(draw,100);
}

function draw()
{
    drawBackground();
    character.draw(); //draws a sprite
}

//this function is called when character is created
Character.prototype.setImage = function ()
{
    this.avatar= new Image();
    this.avatar.onload=function(){
            this.imageLoaded=true;
    };
    this.avatar.src='/img/sprite.png';
}

Character.prototype.draw=function(ctx)
{  
    var imageW=this.imageW;
    var imageH=this.imageH;

    ctx.drawImage(avatar,20,20,imageW,imageH);

}
  • 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-25T16:57:59+00:00Added an answer on May 25, 2026 at 4:57 pm

    Why you try to download background image each time when drawing background? Maybe next code is better:

    var bg=null,ctxDrawInterval=-1;
    init() {
      //stuff
      bg=new Image();
      bg.onload=function(){
        ctx.drawImage(bg,0,0,GAME_WIDTH,GAME_HEIGHT);
        ctxDrawInterval=setInterval(draw,100);
      }
      //bg.onerror=function(){
      //  what if error downloading?
      //}
      bg.src='img/background.png'; // must be placed after bg.onload
    }
    
    function draw() {
      drawBackground();
      character.draw(); //draws a sprite
    }
    
    function drawBackground() {
      ctx.drawImage(bg,0,0,GAME_WIDTH,GAME_HEIGHT);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently doing something like this in some code I'm working on right now:
I am currently doing it like this.. but it gets actually stored as integer..
As I am currently doing this project in only C, I've up untill this
Currently I have a set of markers and I cluster them like this: var
i'm currently doing a project related to AWS and at some point will need
I am currently doing a lot of regression testing at my job. And like
Im currently doing research towards my final year BSc project. The final product will
I'm currently doing this tutorial , but the tutorial uses Glassfish as the server
I'm currently doing this but it doesn't look right to me: spl_autoload_register(function ($class_name){ $class_name
I am currently doing some work for a client which happens to be a

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.