Jump to content

BASIC HELP NEEDED: Display Object String


jw405
 Share

Recommended Posts

Hi all,

 

I have a collection of five bee spritesheets and I have assigned them unique strings such as, 'bee1', 'bee2' etc.

 

I randomly generate a character/bee at the start of each game by:

 

        // Randomly generate an integer and identify unique string
        var randomBee = 'bee'+ this.game.rnd.integerInRange(1,5);
 
 
        // Add sprite
        this.bee = this.game.add.sprite(100, 245, randomBee);
 
HOWEVER, I wanted to display the characters name (top right):
 
        var beeName = getName(randomBeeKey);
 
AND
 
        function getName(beeKey) {
            if(beeKey === "bee1") return "Boobee";
            if(beeKey === "bee2") return "Digbee";
            if(beeKey === "bee3") return "Feebee";
            if(beeKey === "bee4") return "Abbee";
            if(beeKey === "bee5") return "Newbee";
         }
 
I can't seem to get it working, any help would be appreciated!
 
Here's my code if I'm not making sense:
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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