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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:57:46+00:00 2026-06-06T17:57:46+00:00

I have the following code for writing draw calls to a back buffer canvas,

  • 0

I have the following code for writing draw calls to a “back buffer” canvas, then placing those in a main canvas using drawImage. This is for optimization purposes and to ensure all images get placed in sequence.

Before placing the buffer canvas on top of the main one, I’m using fillRect to create a dark-blue background on the main canvas.

However, the blue background is rendering after the sprites. This is unexpected, as I am making its fillRect call first.

Here is my code:

render: function() {
  this.buffer.clearRect(0,0,this.w,this.h);
  this.context.fillStyle = "#000044";
  this.context.fillRect(0,0,this.w,this.h);

  for (var i in this.renderQueue) {
    for (var ii = 0; ii < this.renderQueue[i].length; ii++) {
      sprite = this.renderQueue[i][ii];

      // Draw it!
      this.buffer.fillStyle = "green";
      this.buffer.fillRect(sprite.x, sprite.y, sprite.w, sprite.h);
    }
  }

  this.context.drawImage(this.bufferCanvas,0,0);
}

This also happens when I use fillRect on the buffer canvas, instead of the main one.

Changing the globalCompositeOperation between ‘source-over’ and ‘destination-over’ (for both contexts) does nothing to change this.

Paradoxically, if I instead place the blue fillRect inside the nested for loops with the other draw calls, it works as expected…

Thanks in advance!

Addenum: Changing the composite operation does behave as expected, but not for remedying this specific issue. Sorry for the ambiguity.

  • 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-06T17:57:47+00:00Added an answer on June 6, 2026 at 5:57 pm

    There’s a lot that’s suspect here.

    First off double buffering a canvas does nothing but hurt performance by adding complication, all browsers do double buffering automatically, so if that’s your goal here you shouldn’t be drawing to a buffer.

    Here’s an example of why you don’t need double buffering: http://jsfiddle.net/simonsarris/XzAjv/

    So getting to the meat of the matter, lines of javascript inside a discrete function don’t simply run out of order. Something else is wrong here.

    Setting a breakpoint on the drawImage would solve this pretty much instantly, so if you aren’t familiar with firebug or chrome developer tools I’d highly recommend giving them a look.

    I’m guessing that the “blue” you’re seeing is actually the only thing drawn to your “buffer” canvas and perhaps this.buffer is not actually the buffer context.

    Another possibility is that this.w and this.h are accidentally very small, so that your initial clearRect and fillRect at the start of the method are doing nothing.

    In any case speculation is nowhere near as good as opening up developer tools and actually looking at what’s happening.

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

Sidebar

Related Questions

I am writing code to performance test a web site. I have the following
I have the following section of code in an app that I am writing:
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code for inserting data into database using PDO. It inserts data
I have the following code with a simple class and a method for writing
Writing some classes for a Framework extension, and I have the following code: public
I'm writing some script, that works with web-servers. So, I have the following code:
In Writing CGI Applications with Perl, have following code to log visitors. (my $digits
I am writing in php. I have the following code: $folder_to_zip = /var/www/html/zip/folder; $zip_file_location

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.