npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

superpowers-game-fmouseinput-plugin

v0.3.0

Published

Allows for easy setup of interactions between the mouse and actors in the Superpowers Game system for Superpowers, the HTML5 2D+3D game maker.

Downloads

2

Readme

Superpowers Game fMouseInput component

This plugin makes it super simple to setup interactions between the mouse and actors in the Superpowers Game system of Superpowers, the extensible HTML5 2D+3D game engine.

It exposes the fMouseInput actor component on which mouse input events are emitted whenever the mouse hovers an actor and some mouse button are clicked.

It allows to easily answer questions like these and do something whenever these events happens:

  • is the mouse pointer over my actor now ?
  • did the player clicked on a button while hovering my actor ?
  • has the mouse left my actor ?

Documentation

http://florentpoujol.github.io/superpowers-game-fmouseinput-plugin

You can also access it offline in Superpowers' client with the plugin documentation plugin, or find it directly in the plugin's public/docs folder.

Installation

Download the latest release, unzip it, rename the folder to fMouseInput, move it inside app/systems/supGame/plugins/florentpoujol/ then restart your server.

Advanced:

Get it via npm:

cd app/systems/game/plugins
npm install superpowers-game-fmouseinput-plugin

The name of the vendors or plugins in the app/systems/game/plugins/ folder don't matter.
So you can leave the plugin path as node_modules/superpowres-game-fmouseinput-plugin.

Setup

fMouseInput is an actor component (like a SpriteRenderer) which has to be first placed (via script or the scene editor) on each actors you want to check for interaction with the mouse.

Then, tell the newly placed component which camera the actor should be visible from.

  • If you added the component in the scene editor, sets the camera's actor's name in the Camera field.

Add and setup the component via the scene editor

  • If you added the component by script, pass the camera component, its actor or its name to the camera property.

Example via script :

class MouseInputBehavior extends Sup.Behavior {
  awake() {
    // add the component
    new fMouseInput(this.actor);
    
    // then set the camera
    this.actor.fMouseInput.camera = "MyCamera";
    // or
    this.actor.fMouseInput.camera = Sup.getActor("MyCamera");
    // or
    this.actor.fMouseInput.camera = Sup.getActor("MyCamera").camera;
  }
}

Usage

One way to setup interactions is to check the value of the component's isMouseOver property (which is true or false).

Once you are sure the mouse is over the actor, you can check for mouse button press to create a button for instance.

class MouseInputBehavior extends Sup.Behavior {
  update() {
    if (this.actor.fMouseInput.isMouseOver && Sup.Input.wasMouseButtonJustReleased(0)) {
      // do stuff when the left mouse button has been released
    }
  }
}

You can also listen to several events like mouseEnter or leftClickReleased for instance to make things even easier.
So all you have to do is setup a listener function with the component's on(eventName, listenerFunction) method :

class MouseInputBehavior extends Sup.Behavior {
  awake() {

    this.actor.fMouseInput.on("mouseEnter", () => {
      // do stuff when the mouse just entered the actor
    });

    this.actor.fMouseInput.on("leftClickReleased", () => { this.onLeftClick(); });
  }

  onLeftCLick() {
    // do stuff when the left mouse button has been released
  }
}

Events

You can access the component's event emitter via the emitter property.

this.actor.fMouseInput.on("mouseEnter", () => { ... });
// is the same as
this.actor.fMouseInput.emitter.on("mouseEnter", () => { ... });

Here is the list of the default events that you can listen to:

  • mouseEnter when the mouse wasn't on the actor the previous tick and is on the actor this tick.
  • mouseExit when the mouse was on the actor the previous tick and isn't on the actor this tick.
  • mouseMove when the mouse is on the actor and has moved from the previous tick (it isn't emitted if the mouse in over the actor but doesn't move).
  • leftClickPressed, leftClickDown, leftClickReleased when the mouse is on the actor and the left mouse button was pressed/released during the previous tick or is currently down.
  • middleClickPressed, middleClickDown, middleClickReleased when the mouse is on the actor and the middle mouse button (usually the wheel) was pressed/released during the previous tick or is currently down.
  • rightClickPressed, rightClickDown, rightClickReleased when the mouse is on the actor and the right mouse button was pressed/released during the previous tick or is currently down.
  • wheelUp, wheelDown when the mouse is on the actor and the wheel is turned up or down during this tick.

If you have the need to, the name and behavior of the "click" and "wheel" events can be modified by altering the fMouseInput.eventsData static property.

Misc

The actors you want the mouse to interact with must have some kind of renderer like a sprite renderer.

The interactions happen even when :

  • the renderer has an opacity of 0.
  • the renderer is actually not visible because it is hidden by other renderers in front of him from the camera point of view.

The interactions don't happen when :

  • the actor is hidden with actor.setVisible(false) (or by unchecking the actor's Visible checkbox in the scene editor).
  • the layer the actor is part of is deactivated.

Yet the component's camera property accept a value of type Sup.Camera, Sup.Actor or string, it always return a Sup.Camera component.

An fMouseInput component will be added automatically on the actor with the camera component.