Jump to content

Question about grouping objects


o0Corps0o
 Share

Recommended Posts

Hi,

I've come from an OOP style background with AS3, etc. I'm struggling to work out how to groups things together (kind of like a movieclip in flash). So basically i want to create an object, which will have certain values i can access, but also have created several sprites, and bitmaptext associated with it. Example of how i want to create my object:

 

createNewUpgradeItem:function(myNumber){
       var upgradeItem = new UpgradeItem(this, 25, 200+i*55, GAME_NAME.UpgradesAvailable.name, GAME_NAME.UpgradesAvailable.description, GAME_NAME.UpgradesAvailable.upgradePrice, GAME_NAME.UpgradesAvailable.priceMultiplier, GAME_NAME.UpgradesAvailable.sMultiplier, GAME_NAME.UpgradesAvailable.cMultiplier, i%4);   
        
        GAME_NAME.upgradeMenu.add(upgradeItem);  // Doesn't Work
        upgradeItem._background.events.onInputDown.add(function(){UpgradeItemUpdate(this,upgradeItem);console.log(upgradeItem._name)},this);
    },
 

 

// Where 'i' would be a count (in a for loop) to create several objects. And UpgradesAvailable[] is an array of information to be passed.

 

This works fine i believe and it creates the objects fine and puts them on screen,etc.

 

What i want to do is have this upgradeItem added to a Group (say MenuGroup), so I would have thought something like the following would have worked:

GAME_NAME.upgradeMenu.add(upgradeItem);

 

But it doesn't seem to like it.

 

My UpgradeItem code consists of some things, for example:

 

 

var UpgradeItem = function(game, x, y, upgradeItemName, upgradeDescription, upgradePrice, price, speed, cSpeed, bNumber){
    this._name = upgradeItemName;    
    this._description = upgradeDescription;
    this._upgradePrice = upgradePrice;
    this._pMultiplier = price | 1;
    this._sMultiplier = speed | 1;
    this._cMultiplier = cSpeed | 1;
    this._active = false;
    this._backgroundNumber = bNumber | 1;
        
    this._upgradeItemGroup = game.add.group();    
    GAME_NAME.upgradeMenu.add(this._upgradeItemGroup);
       
    switch(bNumber){
        case 0:
            this._background = game.add.image(x+10, y+36, 'uBackground1');
            break;
        case 1:
            this._background = game.add.image(x+10, y+36, 'uBackground2');
            break;
        default    :
            this._background = game.add.image(x+10, y+36, 'uBackground1');
            break;
    }
    this._background.inputEnabled = true;
    this._background.input.useHandCursor = true;
    this._background.anchor.setTo(0);
    
    this._upgradeItemGroup.add(this._background);
    
    this.UpgradeItemName = game.add.bitmapText(x+30, y+48, 'Lobster',this._name,26,this._upgradeItemGroup);
    this.UpgradeItemName.anchor.setTo(0);
       
    this.UpgradeItemDescription = game.add.bitmapText(x+180, y+48, 'Lobster',this._description,26,this._upgradeItemGroup);
    this.UpgradeItemDescription.anchor.setTo(0);

}

 

You can also see from my code here that i'm trying to group the 'assets' (the text and sprites) into a seperate group.

 

Am I missing something really simple here?
Thanks for looking :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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