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

 Share

  • Recently Browsing   0 members

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