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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:09:50+00:00 2026-05-28T03:09:50+00:00

I have a problem which I can’t find a solution to. I have an

  • 0

I have a problem which I can’t find a solution to. I have an image that I want to draw multiple times on my canvas. For that I have an array for every place I want to draw that image on.

But it seems when JavaScript ought to draw the image something makes the old one disappear? Why?

Here is the code making the troubles:

function drawPoints() {
var map = getMapArray();
var counter = 0;
for(var i = 1; i <= map.length; i++) {
    for(var j = 1; j <= entry.length; j++) { 
        counter++;
        for(var q = 0; q < points.length; q++) {
            if(counter == points[q] && points[q] != 0) {
                var point = new Image();
                point.src="./img/point.png";
                point.addEventListener("load", function(){canvas.drawImage(point, (j-1)*40, (i-1)*40)}, false);
            }
        }
    }
}
}

The logic works perfectly, and it loops through it as it should.
Its the drawimage function inside the eventlistener that doesn’t print the image as I hoped. I don’t know how to do it otherwise?

If you guys have a better solution to this than calling an eventlistener all the time please share your knowlegde. Thanks in advice.

Btw, as I’ve said earlier: the function runs fine but everything is just white, probably due it removes the old image for the new and the interval is too short for me to see any action.

Link to the live script:
http://picturds.com/pacman_serious/

  • 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-28T03:09:51+00:00Added an answer on May 28, 2026 at 3:09 am

    Instead of listening on the image every time you draw, you probably want to:

    1. Store the images in three global variables (pacman, ghost, point)
    2. Start with a loading phase where you load all the images
    3. Once the images are loaded, start your game timer
    4. In the game loop, draw the images directly with canvas.drawImage()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once again I have a problem which I can't find the solution to. A
I have a small problem which I can't seem to find a solution to.
I have a problem which has an solution that can be solved by iteration,
I have a problem which I can't find a solution. I have a Parent
I have a problem which I'm pretty sure that I can't solve without going
I have one problem in which i simply want to know how i can
I have strange problem for which I can't think of a solution. I have
I have a strange problem which I can't fix: A field: private boolean[][][] gaps;
I'm quite new to hibernate and have stumbled on this problem, which I can't
I have a problem which I cant seem to find answer to through searches

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.