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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:00:33+00:00 2026-05-28T06:00:33+00:00

I use this constructor to make objects for a game. Right now, the series

  • 0

I use this constructor to make objects for a game.
Right now, the series of images gets overwritten everytime, such that all the objects look the same on screen.

Here’s the object in question:

function Box() {
    this.ready = false;
    this.pics = pictures;//[];
    this.state = 0;
    this.x = 0;
    this.y = 0;
    this.w = 1;
    this.h = 1;
    this.fill = "#444";
    this.load = function(array){
        var foo = [];
        pictures = [];
        for(var i = 0; i < array.length; i++){
            pictures.push(loadPic(array[i]));
            foo.push(loadPic(array[i]));
        }
        //this.pics = pictures;
        this.pics = foo;
    }
}

The line

this.pics = foo;

seems to do nothing at all.

Also, if I change the initial value of pics to anything but “pictures” (which is a global variable) the game does not start.

Contex: https://github.com/kaninepete/Javascript-Games/blob/images/MVP.js

  • 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-28T06:00:34+00:00Added an answer on May 28, 2026 at 6:00 am

    Initially, you are creating your player and target objects and load their pictures by calling load. Because you are using the object-dot-method syntax, for example player.load to call the functions all references to this should be set as required/expected.

    However to start the game, you are calling reset (for example from myDown). Within reset the objects in player and target are replaced with new instances (notice the calls to addRect). The method load is never called on the new instances and thus both are left with the identical pictures (the global pictures as initially set in Box). Because both are sharing the same array, pictures, they end up being painted the same.

    General advice: I suggest to get rid of the global variables because their dependencies on each other are not obvious. Then you should call the reset function for initialization instead of doubling the implementation on the global level. Try painting a static picture first before introducing event handlers.

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

Sidebar

Related Questions

Can I use default arguments in a constructor like this maybe Soldier(int entyID, int
I have this abstract factory pattern that I use in as3 that I am
In my design I am using objects that evaluate a data record. The constructor
Assuming that I wanted to make a simple dos-based game and I wanted to
I use contructor injection in my solution, but this one class has a property
In this blog article they use the construct: @measured def some_func(): #... # Presumably
I want to use the DbProvider class to construct a generic DAL component. This
use this website a lot but first time posting. My program creates a number
I use this tool called Lazy C++ which breaks a single C++ .lzz file
I use this line in my .htaccess file to automatically add a trailing slash

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.