Jump to content

Creating multiple popups with too many functions?


HollyBlade
 Share

Recommended Posts

I have a question. I'm creating multiple "popups" in my game that's triggered with different buttons. Right now I have 5 functions  4 of them are basically the same thing. Closewindow, openwindow, closewindow1 and openwindow1. The only difference is that they correspond to different popups. Is there a more elegant solution (if that's the right word) than what I have right now. I plan on adding more so I feel like there's another way I just don't know what it is. I've looked at groups but don't items in groups have to be all doing the same thing?   I attached my code if it helps.  

Thanks  

Screen Shot 2018-03-01 at 12.51.50 PM.png

Link to comment
Share on other sites

function windowCloserOpener(_window,action){

 if ((tween && tween.isRunning) || _window.scale.x === 1){
   return;
}
if (action === 'open'){
   tween = game.add.tween(_window.scale).to ( { x:1, y: 1}, 1000; Phaser.Easing.Elastic.Out, true);
}else if (action ==='close') { 
   ......
  }
}

//and then make the callbacks like that:

popup2.events.onInputDown.add(function(){windowCloserOpener(popup2,'open')},this);

// you need to call your function in another function in order to pass it parameters


 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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