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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:23:55+00:00 2026-06-15T22:23:55+00:00

I have an HTML5 game project I’m currently working on, and since Arial didn’t

  • 0

I have an HTML5 game project I’m currently working on, and since Arial didn’t seem fancy enough for the interface, I have been trying to get two Google Webfonts working, in order to enhance my game design.

I am trying to use these in context.fillText calls from my game canvas, but I’m facing a weird issue for which I couldn’t find any explanation.

Actually the fonts seem to randomly be, or not be downloaded (or initialized? I can’t be sure) correctly.
This is not about the cache, and I couldn’t find a “rule” of behavior to identify this by troubleshooting. Sometimes the fonts are loaded just fine the first time, and the second time, and then I can never have them showed again until I empty the cache once or twice. But this, naturally, is just an example.

I have a little piece of text that I put at the bottom of my canvas (browser comaptibility blah blah blah) in my html, which I’ve set to one of the two webfonts, and it is always rendering just fine so I can confirm this bug is entirely about canvas.

At the moment, I have those steps in my code regarding fonts handling:

HTML:

   <link href='http://fonts.googleapis.com/css?family=Londrina+Solid|Luckiest+Guy' rel='stylesheet' type='text/css'>
   <link rel=StyleSheet href="style.css" type="text/css">

CSS (a part of my style.css file):

    canvas {
...
    font-style: "Londrina Solid", "Luckiest Guy";
...
}

As you can see I tried to apply whether one or the other font to the canvas, which is a DOM element (as I read it could help things to work, on another stackoverflow post) but that didn’t change a thing.

JS:

    var fontsReady = false;
    var starting = false;
    // check if the game isn't already starting this variable is about timeOut)

    WebFontConfig = {
        google: {
            families : ['Luckiest Guy', 'Londrina Solid']
        },

        active: function() {
            console.log('All fonts are now loaded');
            fontsReady = true;
        }

    }

    var webFontsInit = function() {
            var wf = document.createElement('script');
            wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
        '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
            wf.type = 'text/javascript';
            wf.async = 'true';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(wf, s);
          }();

    function checkReady () {
            if (document.readyState === "complete" && fontsReady == true && starting == false) {
                console.log('States are OK');
                starting = true;
                ctx.save();
                titleScreen();
                }
            }
            else 
                setTimeout(checkReady, 500); // i think this timeout is needed, to regularly check for the game loading states (such as fontsReady)
        }

I’m testing my game on Google Chrome, and I’m using the Google Webfonts Loader snippet.
When I check the CSS while starting the game, everything runs smoothly, my loading screen (which I wrote in a standard web font to let the user know he has to wait a bit) is waiting for the fonts and the assets to be loaded (I can see the matching classes in my CSS) and the title screen doesn’t start animating until they are loaded.

Still, sometimes the fonts get displayed and sometimes they don’t and I can’t even see the frame I also display on title screen. I can’t understand why. I just have my background drawing, and no errors in the console.

Another weird part of my issue is that whenever I get the case where my Title Screen stays empty, and I have a dev tool open (such as the Chrome one I open with F12), whenever I close it, the fonts and the drawing on my title screen magically appear. I really don’t know why.

Any help would be greatly appreciated, if further information is needed, please ask me!

  • 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-15T22:23:57+00:00Added an answer on June 15, 2026 at 10:23 pm

    Ok, nevermind. I found out the real problem was that I hadn’t explicitly set the z-index for the two canvas I had (two layers).
    It looks like the z-index, if not set in the CSS, is set by Chrome according to which element appeared first, unlike Firefox or IE. Those two create elements in the order of the html code, this is why I didn’t encounter any problems of this kind with IE9 or FF.

    So, this is where the “random” in my problem came from… Now everything looks fine.

    Here is the bit of CSS I have now, for setting two canvas “layers” overlapping each other with proper z-indexes :

        canvas {
            width: 320px; // those are my canvas' dimensions, put your own!
            height: 500px;
            position: absolute;
            font-style: "Londrina Solid", "Luckiest Guy";
            left: 50%;
            margin-left: -160px; // this is my trick for centering layers in the page
            top: 0;
            outline: 0;
            border: 1px solid #000;
            display:block;
        }
    
        #c {
            z-index:0;
        }
    
        #c2 {
            z-index:1;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on one html5 game project. In this I have to control
I'm working on a HTML5 game and have what I think is a math
I have been developing a game in the HTML5/Javascript new canvas feature, and all
I'm working on an HTML5/JavaScript game engine, and I have started to encounter a
I have a very simple HTML5 game that works as expected from a regular
I have built a game in HTML5 and a web form posts data to
I am making a game engine using HTML5 canvas, and I have decided to
I'm currently developing my first android app, and my first game. I've been developing
People have been saying so many good words for HTML5, but one of my
OK, so I have created an HTML5 canvas game that uses localStorage. I have

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.