Anahit DEV Posted September 25, 2017 Share Posted September 25, 2017 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. Link to comment Share on other sites More sharing options...
samid737 Posted September 25, 2017 Share Posted September 25, 2017 In Phaser , you can add sprites to a group and use setAll to change properties of those sprites, you can use forEach() or callAll() : In general, to repeat certain code, you can use for loops. Link to comment Share on other sites More sharing options...
Anahit DEV Posted September 25, 2017 Author Share Posted September 25, 2017 Great. Thank you very much for the working snippet and advise. samid737 1 Link to comment Share on other sites More sharing options...
Anahit DEV Posted September 26, 2017 Author Share Posted September 26, 2017 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. Link to comment Share on other sites More sharing options...
samid737 Posted September 26, 2017 Share Posted September 26, 2017 Normally that can happen if you change the position and pivot, scale or rotation of the group and then add a sprite. Try transforming the group after adding all sprites otherwise, you can try using world coordinates? Link to comment Share on other sites More sharing options...
Anahit DEV Posted September 26, 2017 Author Share Posted September 26, 2017 I tried with world @samid737 but is not really working. What you mean by 40 minutes ago, samid737 said: transforming the group after adding all sprites Cant i just group them without changing anything in their current parameters? Thanks Link to comment Share on other sites More sharing options...
samid737 Posted September 26, 2017 Share Posted September 26, 2017 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? Link to comment Share on other sites More sharing options...
Anahit DEV Posted September 26, 2017 Author Share Posted September 26, 2017 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; }; Link to comment Share on other sites More sharing options...
samid737 Posted September 26, 2017 Share Posted September 26, 2017 My guess is alignIn displaces the sprite. If you have some fixed amount of sprites that need to be aligned in a grid, one idea is to re-arrange sprites using group.align() instead of the extra rectangle. Link to comment Share on other sites More sharing options...
Recommended Posts