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

phaser-move-and-stop-plugin

v1.1.1

Published

Phaser plugin to move an object and stop it at an exact position

Downloads

10

Readme

phaser-move-and-stop-plugin

phaser plugin to move an object and stop it at an exact position. Compatible with phaser >= 2.0.0 <3.0.0

Motivation

As I didn't find a way in the phaser core functions to move an item to stop at a given position, I made this plugin. It just wrap the phaser core function moveToXY to have the displayed object stop when the x/y position is reached.

Installation

$ npm install phaser-move-and-stop-plugin

Usage

First add the plugin to game in your main create() function of your phaser state:

import MoveAndStopPlugin from "phaser-move-and-stop-plugin";

export default game => ({
	create: () => {
		game.moveAndStop = game.plugins.add(MoveAndStopPlugin);
	},
	update: () => {
		//...
	}
});

Then call one the the following api:

API

game.moveAndStop.toXY(displayObject, x, y, speed, maxTime, events)

It it same as phaserJS moveToXY except that the object will stop at the exact x/y position.

Arguments

  • [displayObject(state, [ownProps]): any]: The display object to move.
  • [x: number]: The x coordinate to reach.
  • [y: number]: The y coordinate to reach.
  • [speed: number (optional)]: The speed it will move, in pixels per second (default is 60 pixels/sec)
  • [maxTime: number (optional)]: Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
  • [events: object (optional)]: List of events to trigger.

Example

game.moveAndStop.toXY(item, x, y, 5000, null, {
  onStopped: () => {
    console.log('stopped before reaching position!');
  },
  onPositionReached: () => {
    console.log('position reached!');
  }
});

game.moveAndStop.toObject(displayObject, destination, speed, maxTime, events)

It it same as phaserJS moveToObject except that the object will stop at the exact destination position.

Arguments

  • [displayObject(state, [ownProps]): any]: The display object to move.
  • [destination: any]: The display object to move towards. Can be any object but must have visible x/y properties.
  • [speed: number (optional)]: The speed it will move, in pixels per second (default is 60 pixels/sec)
  • [maxTime: number (optional)]: Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the object will arrive at destination in the given number of ms.
  • [events: object (optional)]: List of events to trigger.

Example

game.moveAndStop.toObject(item, dest, 5000, null, {
  onPositionReached: () => {
    console.log('position reached!');
  }
});

game.moveAndStop.stop(displayObject)

Stop the object

game.moveAndStop.isItemMoving(displayObject)

return true is the object is moving

Function Events

onStopped(displayObject){}

Function called when the object stopped. This function is call if the object stopped at the targetted position or stopped before reaching it.

onPositionReached(displayObject){}

Function called when the object reach the targetted position