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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:02:07+00:00 2026-06-05T11:02:07+00:00

I am drawing image which is loaded using loader method in two different places.

  • 0

I am drawing image which is loaded using loader method in two different places. But it only displays the second one. (I am following this http://www.html5canvastutorials.com/tutorials/html5-canvas-image-loader/)

If I add an alert() it works in Fx but not in Chrome. I want it to work everywhere without alert()

If I try drawing Image without using preloaded image I am getting the desired result. But I am thinking it is extra load (http://www.html5canvastutorials.com/tutorials/html5-canvas-images/)

ImageOnload(“O”,120,120); //This image not displaying

alert(“If i add alert it works only in Fx but not in Chrome”)

ImageOnload(“O”,120,20);//only this is displaying ???

<html>
    <head>
    </head>
    <script type="text/javascript" >
        var ctx;
        var ImageVariable={};

        window.onload= function()
        {
            var canvas = document.getElementById("gameLoop");   
            ctx = canvas.getContext("2d");

            ImageBuilder(ImageSourceDB);
            ImageOnload("O",120,120); //This image is not displaying
                    //alert("If i add alert it works only in FFox but not in chrome")
            ImageOnload("O",120,20);  
        }

        var ImageSourceDB=
        {
            X:"./Images/X.gif",
            O:"./Images/O.gif"
        }
        function ImageBuilder(ImageSrcDB)
        {
            for (iSrc in ImageSrcDB)
            {
                ImageVariable[iSrc]= new Image();   
                    ImageVariable[iSrc].src = ImageSrcDB[iSrc];
            }
        }

        function ImageOnload(ImageSrc,x,y)
        {
            ImageVariable[ImageSrc].onload= function ()
            {
                ctx.drawImage(ImageVariable[ImageSrc],x,y);
            };          
                    ImageVariable[ImageSrc].src = ImageSourceDB[ImageSrc];
        }
    </script>
    <body>
        <canvas class ="pattern" id="gameLoop" height="300"  width="300" />
    </body>
</html>

List item

  • 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-05T11:02:09+00:00Added an answer on June 5, 2026 at 11:02 am
    ImageOnload("O",120,120); //This image not displaying
    ImageOnload("O",120,20);//only this is displaying ???
    

    You forgot to change the id of the object:

    ImageOnload("O",120,120);
    ImageOnload("X",120,20); // Use "X", not "O"!!!
    

    If you still want to show “O” twice, then you should draw it twice, but with only one onload function. See example below:

    <script type="text/javascript" >
        var ctx;
        var ImageVariable={};
        var ImageSourceDB = {
            X:"./Images/X.gif",
            O:"./Images/O.gif"
        }
    
        window.onload = function() {
            var canvas = document.getElementById("gameLoop");   
            ctx = canvas.getContext("2d");
    
            ImageBuilder(ImageSourceDB);
    
            ImageVariable["O"].onload = function() {
                // this will be executed when the image "O" is loaded
                // this is a pointer to ImageVariable["O"]
                ctx.drawImage(this, 120, 120);
                ctx.drawImage(this, 120, 20);
            }
            ImageVariable["X"].onload = function() {
                // this will be executed when the image "X" is loaded
                ctx.drawImage(this, 30,  30);
            }
        }        
        function ImageBuilder(ImageSrcDB) {
            for (iSrc in ImageSrcDB) {
                ImageVariable[iSrc]= new Image();   
                ImageVariable[iSrc].src = ImageSrcDB[iSrc];
            }
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm drawing an image using rgb pixel data. I need to set transparent background
I'm drawing a transparent rendered image on top of a background image which is
I have a grayscale image which I want to use for drawing Cocoa controls.
Is it possible to use the FromStream method of System.Drawing.Image without having to keep
I'm using System.Drawing.Image in .Net to do a simple conversion from png to jpeg.
I am using GDI+ on the server-side to create an image which is streamed
Does someone know what might go wrong, when you attempt to compare two System.Drawing.Image
here is my image width and size code which is work perfectly but problem
I'm drawing certain images in WPF which will be displayed by a game (developed
I have a System.Drawing.Image in my program. The file is not on the file

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.