Creating multiple popups with too many functions?

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.  


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

Share this post

Link to post
Share on other sites
function windowCloserOpener(_window,action){

 if ((tween && tween.isRunning) || _window.scale.x === 1){
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:


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


Share this post

Link to post
Share on other sites

I'm a little confused, I'm pretty new to phaser. The buttons are the ones that open and close the individual popups and you can click on the popups to close them. So should that be done with the buttons instead? 

Share this post

Link to post
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.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.