Anahit DEV

How to set same style to multiple elements with one line of code

Recommended Posts

Hello to all coders,

I need to add same styling to multiple elements/variables. How i can write the code/syntax in Phaser so i do that with one line of code not 100s lines for same thing. For example

 

basicTableJackpotSymbolOn.alpha = 0;
game.add.tween(basicTableJackpotSymbolOff).to({alpha: 1}, 500, "Linear", true);
basicTableBarSymbolOn.alpha = 0;
game.add.tween(basicTableBarSymbolOff).to({alpha: 1}, 500, "Linear", true);
basicTableMelonSymbolOn.alpha = 0;
		            	
basicBetYellowRectV2N3Point.fill = '#999999';
basicBetYellowRectV2N4Point.fill = '#999999';
basicBetYellowRectV2N5Point.fill = '#999999';
basicBetYellowRectV2N6Point.fill = '#999999';

 

Thanks in advance.

Share this post


Link to post
Share on other sites

Hey @samid737 

I was testing the code with some elements and noticed that after grouping they are changing their defined positions(x,y tec) so after grouping they appear not in their previously defined positions.

Any way of avoiding this issue please?

Thanks in advance.

Share this post


Link to post
Share on other sites

 

 

Transforming is rotating scaling, positioning/moving your group. Yes you can definitely do that, but if you transform your group it might be that your sprites will not have the position that you pass as A parameter. This might not be your issue though. Do you have an example of your code?  

Share this post


Link to post
Share on other sites

Yes here it is @samid737

basicTableJackpotSymbol = game.add.sprite(0, 0, 'basicTableJackpotSymbol');
basicBetInnerWrapRect.addChild(basicTableJackpotSymbol);
basicTableJackpotSymbol.alignIn(basicBetLeftRectV1N2, Phaser.CENTER);
basicTableJackpotSymbol.frame = 0;

activateBasicPSymbols = game.add.group();
activateBasicPSymbols.addMultiple([basicTableJackpotSymbol,basicTableBarSymbol,basicTableMelonSymbol,basicTablePlumSymbol,basicTablePearSymbol,basicTableRaspberrySymbol,basicTableAppleSymbol,basicTableOrangeSymbol,basicTableLemonSymbol,basicTableCherrySymbol,basicTableSignSymbol], false);
activateBasicPSymbols.forEach(activateBasicPSymbolsFunc,this);
function activateBasicPSymbolsFunc(activatedSymbol){
	activatedSymbol.frame = 0;
};

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.