Sign in to follow this  

Question about grouping objects

Recommended Posts


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:


       var upgradeItem = new UpgradeItem(this, 25, 200+i*55,, 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{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:



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 =;    
        case 0:
            this._background = game.add.image(x+10, y+36, 'uBackground1');
        case 1:
            this._background = game.add.image(x+10, y+36, 'uBackground2');
        default    :
            this._background = game.add.image(x+10, y+36, 'uBackground1');
    this._background.inputEnabled = true;
    this._background.input.useHandCursor = true;
    this.UpgradeItemName = game.add.bitmapText(x+30, y+48, 'Lobster',this._name,26,this._upgradeItemGroup);
    this.UpgradeItemDescription = game.add.bitmapText(x+180, y+48, 'Lobster',this._description,26,this._upgradeItemGroup);



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 :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.