Jump to content

Checking an attribute in a Class


Conqarous
 Share

Recommended Posts

Hey guys,

 

How can I get the 'index' attribute from a class to use it in a for loop?

 

new stars are pushed into starsList = [];

'p_id' here is compared to the 'index' value in starsList

 

starsList.star.id or starsList.id do not work, what is the correct way? I'm a total newbie. Thanks in advance!

 

function  (p_id) {
        
        for (i = 0; i < starsList.length; i++) {
        
                if (p_id == starsList.star.id) {
                   
                    starsList.y = starsList.y - 10;
                
                    break;
                }
            }
    }

 

And here is the class:

 

Star = function (index, game) {

    var x = 50;
    var y = 50;

    this.game = game;
    this.star = game.add.sprite(x, y, 'star', 'star1');

    this.star.id = index;

    };

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...