Jump to content

How to Display html popup in phaser as popup on sprite click


gambler
 Share

Recommended Posts

There are several ways to display a modal or pop up, using CSS libraries like Bootstrap and Semantic UI. 

So, for example, if you have a sprite, you need to first enable Input on it within Create, then handle the event when it is clicked. The event will then call a function, and within the function, you display the pop up.

var sprite;

function create () {

sprite=game.add.sprite( X, Y, 'mySprite');

sprite.inputEnabled=true; //enable input on the sprite;

sprite.events.onInputDown.add(showPopUp, this) ; //set what function to do when it is clicked;

 

}

 

function showPopUp ( ) {

$('.ui.modal').modal('show'); //JQuery method to call the modal in Semantic UI.

}

 

Of course, in your index.html, you should link the scripts to your head portion.

 

 

Link to comment
Share on other sites

Hello, the possible solution can be js or jquery, but the interactivity will be lost with the (canvas) game, it's better put elements in layers, groups or others, and change states for this visible or not (simply without animations).

At the beginning:
overlay.visible = false;

For use:
overlay.visible = true;

Or look this for animate:

https://developer.mozilla.org/en-US/docs/Games/Tutorials/2D_breakout_game_Phaser/Animations_and_tweens

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

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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