TijmenH Posted June 11, 2015 Share Posted June 11, 2015 Hello, I've got a function where I pass groupName as parameter. Now I want to create a sprite like this:object = groupName.create( x, y,objectImage);but it doesn't read the groupName as parameter/variable. It just looks for a function called groupName.create. How can I make sure javascript replaces the groupName with the string that's passed as parameter? Thanks in advance! Link to comment Share on other sites More sharing options...
drhayes Posted June 11, 2015 Share Posted June 11, 2015 You can't. I'm assuming "groupName" is a string, like the actual variable you passed to "game.add.group"? That won't work. What you *could* do is make a new variable, "name2Group = {};" and then do something like "name2Group[groupName] = game.add.group(game.world, groupName);". Then you can say "name2Group[groupName]" later and get the group back. Link to comment Share on other sites More sharing options...
TijmenH Posted June 15, 2015 Author Share Posted June 15, 2015 Ah, I see. Too bad, I fixed it another way using a switch statement. Maybe not the best option but it would be too much reworking to have your solution working. I already did a switch statement for all the groups (so if groupName is 'hunters' it already had some group specific code to scale, set animations etc) I just create the objects for the groups in there now. Thanks for helping me! Link to comment Share on other sites More sharing options...
Recommended Posts