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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:52:43+00:00 2026-05-25T10:52:43+00:00

Hi am making a small HTML5 canvas demo. I initiated the canvas using modernizer

  • 0

Hi am making a small HTML5 canvas demo.

I initiated the canvas using modernizer from O’Reilly’s HTML5 text.

This is for iPad so my canvas is 1024 by 768.

I then load in a background image in my DrawScreen function.

var backgroundImage = new Image();
backgroundImage.src = "images/background.jpg";
backgroundImage.onload = function(){
    context.drawImage(backgroundImage,0,0);
}

I want to add text to this then. So I do:

function drawText(){
    context.fillStyle ="gray";
    context.font = "28px Helvetica";        
    context.fillText(message, 260, 700);
}

I then call both functions:

    DrawScreen();
    DrawText();

However my background image totally over writes my text. Or is on top of it. If I disable DrawScreen(); I can see the text. Changing the function order doesn’t make a differnce…

How to do this? I feel so stupid that am stuck on something that seems so elementary.

Thanks

  • 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-25T10:52:44+00:00Added an answer on May 25, 2026 at 10:52 am

    The problem is that your image is being drawn after — and therefore on top of — your text. This is because of the time it takes the image to load. Basically, what’s happening is this:

    • You call your DrawScreen function
    • You start loading your background image by assigning the src attribute
    • You assign the onload() handler to fire once the image has finished loading.
    • DrawScreen exits, having completed all its work
    • You call DrawText, which immediately draws the text
    • At some point later, the image finishes loading, fires the onload() event, and you draw the background image.

    I’d suggest restructuring your code so that all the drawing is kicked off by the successful loading of the image. That way, nothing asynchronous will be going on, and the image will be drawn, followed by the text.

    Here’s a quick example, on jsFiddle.

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

Sidebar

Related Questions

I'm making a small game using the HTML5 canvas element. It works great, except
I'm making small module/plugin for my future CMS/Framework. I wanted it from begining to
I am designing a small website using HTML + JSP. This is my first
I'm working on making a skeleton from which to build small to medium-sized sites
i am making a small tooltip feature for my site i had this working
I'm making a small Adobe AIR app (my first) using HTML+Javascript. I need to
I've been making small scale projects for a while now. I haven't started a
Im making a small python script to upload files on the net. The script
im making a small smiley script , what it does is to change ::1::
I'm making a small web application in Seaside. I have a login component, and

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.