Phaser2 – Prefab: Hyperlink

Dear friendy reader,

nice to see you around here. I publish these articles for free and it would be very kind of you to support my blog. You can start by disabling your AdBlocker. That would mean a lot to me and will help to finance this blog.

Best regards, J. Wiese

The following small prefab is a modified Phaser.Text Object. It enables the input, changes the mouse cursor and will open a provided link in a new window, if the text will be clicked. Popup-blocker seem to block this, because the new window is no direct result of the “click”.

class Link extends Phaser.Text {
    constructor(game, x, y, text, url, style) {
        super(game, x, y, text, style);
        this.url = url;
        this._oldFill = null;

        //add custom objects to the game;
        //Activate inpute events
        this.inputEnabled = true;
        //Change hover cursor
        this.input.useHandCursor = true;
        //Listen to the events,this);, this);, this);

    onOver() {
        this._oldFill = this.fill;
        this.fill = "blue";

    onOut() {
        this.fill = this._oldFill;

    onClick() {, "_blank");

Easy to use:

let someLink = new Link(, 0, 0, "Link text", "", {});


Leave a Reply

Your email address will not be published.